1

I need to add a suffix text to the price of a woocommerce product while on WooCommerce cart.

Based on How to add suffix text to price in WooCommerce cart and checkout page? answer, so I'm trying to adapt that code to recognize product categories.

I am also using has_product_categories() custom conditional function from this answer.

Here is my code:

add_filter( 'woocommerce_cart_item_price', 'kd_custom_price_message' );
add_filter( 'woocommerce_cart_item_subtotal', 'kd_custom_price_message' );  
add_filter( 'woocommerce_cart_subtotal', 'kd_custom_price_message' );  
add_filter( 'woocommerce_cart_total', 'kd_custom_price_message' ); 
function kd_custom_price_message( $price ) {

    if( is_cart() && has_product_categories( '46' ) ){
        $afterPriceSymbol = ' Monthly';
        return $price . $afterPriceSymbol;
        } else {
        return $price;
    }
}

Sadly I keep getting the following error:

Fatal error: Uncaught ArgumentCountError: Too few arguments to function has_product_categories()

I haven't been able to either combine the two (as in including the suffix one here) or adapt this one to the suffix text one.

Any clue what I'm missing?

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
Ñako
  • 33
  • 2
  • 1
    The custom function `has_product_categories()`requires 2 arguments to be passed in. You are just passing the product ID in it but you need to pass also the targeted product categories terms in it a second argument. – LoicTheAztec Mar 10 '21 at 04:19

0 Answers0