0

I want to change my download button for non logged in users. Instead of the download button I want to show a custom HTML code with message to login/register. The below code is hiding the button but the injection of the new HTML code is not working.

<?php if (!is_user_logged_in()) : ?>
<style>
    .product-purchase-box{
        display: none;
    }
</style>
<script>
<p><a href="https://ezcliparts.com/login">LOGIN</a> OR <a href="https://ezcliparts.com/register">REGISTER</a> FOR FREE TO ACCESS THIS AND ALL 1 MILLION+ DESIGNS</p>
</script>
<?php endif; ?>

Target Page: ezcliparts.com/downloads/seamless-geometric-digital-paper-pattern-abstract-hand-drawn-background

Original Download Button Output:

<div class="cart-box row product-purchase-box" style="user-select: auto;">
    <div class="col-md-12 paading-left-0 product-price" style="user-select: auto;">
        <h3 style="user-select: auto;"><span class="edd_price" id="edd_price_4701" style="user-select: auto;">$0.00</span></h3> </div>
    <div class="product_widget_inside" style="user-select: auto;"> <a href="#" class="edd-free-downloads-direct-download-link button white edd-submit" data-download-id="4701" style="user-select: auto;">Download</a> </div>
</div>

I created the website with the help of a developer but the contract is over so I have to do it myself now.

2
  • How is the original download button being output? Also, where are you putting this code? This is PHP, not HTML, so it will not work if you put it into the editor. Commented Sep 14, 2021 at 16:16
  • I am adding the PHP code in "header.php" file in my themes directory. And for reference I am adding The Original HTML code of the target class in my question. Commented Sep 14, 2021 at 16:21

1 Answer 1

0

One way to handle this with the approach you've taken is to expand on the PHP code for the check to see if the user is logged in like so:

<?php if (!is_user_logged_in()) : ?>
<style>
  .product-purchase-box{display: none;}
  .linktologin{display: inline;}
</style>
<?php else : ?>
<style>
  .product-purchase-box{display: inline;}
  .linktologin{display: none;}
</style>
<?php endif; ?>

Then, remove the HTML code for the login link within the <script> tags and add it to where you have the button HTML with the class .linktologin (or whatever you chose). Something like this:

<div class="cart-box row product-purchase-box" style="user-select: auto;">
  <div class="col-md-12 paading-left-0 product-price" style="user-select: auto;">
    <h3 style="user-select: auto;"><span class="edd_price" id="edd_price_4701" style="user-select: auto;">$0.00</span></h3>
  </div>
  <div class="product_widget_inside" style="user-select: auto;"> <a href="#" class="edd-free-downloads-direct-download-link button white edd-submit" data-download-id="4701" style="user-select: auto;">Download</a></div>
</div>
<div class="linktologin">
  <a href="https://ezcliparts.com/login">LOGIN</a> OR <a href="https://ezcliparts.com/register">REGISTER</a> FOR FREE TO ACCESS THIS AND ALL 1 MILLION+ DESIGNS
</div>
3
  • I search all the files in notepad++ but didn't found the HTML. Where can I find this HTML file. Any Idea? Commented Sep 15, 2021 at 5:31
  • Is it possible to append the HTML through PHP header.php? Commented Sep 15, 2021 at 5:34
  • If you're not finding the HTML code in any file, then it could be within the post content. I suggest looking at the HTML (or text) view of the post in question to see if you can find and update the button HTML code as I suggested.
    – ScottM
    Commented Sep 15, 2021 at 12:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.