简体   繁体   中英

How to get my PHP Code Snippets work on my Wordpress website?

I am adding Prev and Next buttons to my Single Product Page on my Wordpress website with Woocommerce. I see that my code is working when I add it in my function.php but when I am trying to add it via PHP Code Snippet on my page it doesn't work. Can someone please help me with this?

ps I'm using PHP Code Snippets by XYZ PHP Code so I could put these buttons where I want, because otherwise if I use it in function.php it puts them only at the top of the page.

<?php
add_action( 'woocommerce_before_single_product', 'guzzz_prev_next_product' );

function guzzz_prev_next_product(){

echo '<div class="prev_next_buttons">';
    
   // 'product_cat' will make sure to return next/prev from current category
       next_post_link('<p style="float:right;">%link</p>', 'NEXT &rarr;', TRUE, ' ', 'product_cat');
       previous_post_link('<p style="float:left;">%link</p>', '&larr; PREVIOUS', TRUE,' ', 'product_cat');

echo '</div>';

    }

I used the hook 'woocommerce_product_thumbnails' and kept the code in function.php. So my links are now where I want them to be, beneath the product image.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM