Remove product content based on category

You are here:

Add this code to your child theme’s functions.php file or via a plugin that allows custom functions to be added, such as the Code snippets plugin. Avoid adding custom code directly to your parent theme’s functions.php file, as this will be wiped entirely when you update the theme.

The following code will remove product images on single product pages within the ‘Cookware’ category:

  /**
  * Remove product content based on category
  */
  add_action( ‘wp’, ‘remove_product_content’ );
  function remove_product_content() {
  // If a product in the ‘Cookware’ category is being viewed…
  if ( is_product() && has_term( ‘Cookware’, ‘product_cat’ ) ) {
  //… Remove the images
  remove_action( ‘woocommerce_before_single_product_summary’, ‘woocommerce_show_product_images’, 20 );
  // For a full list of what can be removed please see woocommerce-hooks.php
  }
  }
Was this article helpful?
Dislike 0
Views: 11