Add text or prefix before/after price in WooCommerce catalog page


I would like to add a small bit of text, preferably after, the price of an item in the WooCommerce catalog/shop page.

I found this snippit online, which works quite well, but it also adds the text in the single product page and that’s something I’d like to avoid. It should only show on the shop page with all the products.

//Add in text after price to certain products
function themeprefix_custom_price_message( $price ) { 
    global $post;
    $product_id = $post->ID;
    $my_product_array = array( 3016  );//add in product IDs
    if ( in_array( $product_id, $my_product_array )) {
        $textafter = '(voor 50cl)'; //add your text
        return $price . '<br /><span class="price-description">' . $textafter . '</span>';
    else { 
        return $price; 
add_filter( 'woocommerce_get_price_html', 'themeprefix_custom_price_message' );

Inside this part of the snippet I should add all of the product ID’s where it should show, but it should show after each product in the catalog list. Of course I can just add all ID’s, but this causes it to also show on the single product page.

$my_product_array = array( 3016  );//add in product IDs

My coding is not advanced enough to make the necessary changes or to avoid it from being show on individual product pages. Any assistance is appreciated!

Jordy Steyaert 2 months 0 Answers 6 views 0

Leave an answer