1

I use the following snippet to display extra text after the price in WooCommerce:

add_filter( 'woocommerce_get_price_html', 'custom_price_message' );
function custom_price_message( $price ) {
  $new_price = $price . ' <span class="price-text">' . __('with shipping').'</span>';
  return $new_price;
}

But now it shows on every product page. Is it possible to exclude a certain product category from this? Not all products include shipping. So I thought I'd make a new category named "Pick up only", place all the products that don't have shipping in there and exclude that category from the above snippet. However, I don't know how to do this... Can anyone point me in the right direction?

Much appreciated!

Regards, Stefan

1 Answer 1

0

Since product category is a taxonomy, you could try the is_tax() function. Check for the current category and then manipulate the data:

add_filter( 'woocommerce_get_price_html', 'custom_price_message' );
function custom_price_message( $price ) {
  // Check the current category
  if ( ! is_tax ( 'product_cat', 'category name or id here' ) {
      $price .= ' <span class="price-text">' . __('with shipping').'</span>';
  }
  return $price;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.