admin管理员组

文章数量:1287670

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>

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>
Share Improve this question asked Sep 14, 2021 at 10:00 Katherine Elizabeth KathKatherine Elizabeth Kath 32 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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; ?>

本文标签: phpHide A Class and Add Custom HTML Code Using Wordpress