0

In my wordpress website I am trying to hide download button from non logged-in user and add a custom HTML to that section. My current code is hiding the download button but not displaying the text. I am a beginner PHP programmer so any help is really appreciated.

I am using this code:

<style>
<?php if(! is_user_logged_in() ) : ?>
    .product-purchase-box{
        display: none;
        $(".single-product-widget").text("Please Login/Register To Download");
    }
<?php endif; ?>
</style>

1 Answer 1

0

You mixed JavaScript code with css.

Going by the code you provided you would need to do this.

<?php if (!is_user_logged_in()) : ?>
<style>
    .product-purchase-box{
        display: none;
    }
</style>
<script>
    ($ => {
        $(".single-product-widget").text("Please Login/Register To Download");
    })(jQuery);
</script>
<?php endif; ?>

6
  • This is my target website: ezcliparts.com/downloads/geometric-hand-drawn-stylish-texture-pattern-abstract-seamless-background/ Commented Sep 14, 2021 at 11:08
  • @KatherineElizabethKath I don't understand how this is relevant, could you explain? How is this link/comment relevant to your question or my answer? Commented Sep 14, 2021 at 11:27
  • Sorry for late replay. I tried the code on that provided link page. But it didn't had any reflection on the target element. May be the class I am targeting is wrong (I am trying to replace the "PURCHASE" text). Can you help me please Commented Sep 14, 2021 at 12:56
  • Seem to work fine. It hides the element with the class .product-purchase-box using the css and it changes that element inner content to Please Login/Register To Download. Here is the console (google DevTools) of the element Commented Sep 14, 2021 at 13:02
  • I sent you the link to show the reflection of the change. There is nothing changed Commented Sep 14, 2021 at 13:42

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.