WooCommerce: Override Single Product Settings e.g. Enable Reviews
VIA BUSINESS BLOOMERS

WooCommerce: Override Single Product Settings e.g. Enable Reviews

In WooCommerce, everything is easy until you have a dozen products to manage. But once you start scaling, and maybe need to import hundreds of items, right then is when you go looking for shortcuts.

Problem is – there are single product settings that you must enter manually for each product (or do it in bulk anyway) such as tax status, tax class, shipping class, sold individually, enable reviews and more; you could keep repeating your manual setup operations or fine-tune your bulk editor system to get that done, but what if there were a few lines of code that would simply “set” whatever option you need for ALL products, without bothering whether that specific option is set or not set in the single product edit page?

For example, it happened to a client of mine that we forgot to “enable reviews” on 10,000 imported products so we were left with two choices: re-run the product import, or find something smarter. And the latter is what we’ll cover today.

So, how do you “override” or “force” a specific WooCommerce single product setting without worrying about its actual per-product value, so that products do behave all the same? Here are a couple of ideas. Enjoy!

PHP Snippet 1: Force “Enable Reviews” to All Products

In this case it gets a little tricky, but once you study how reviews are triggered on the single product page, the result is just 7 lines of PHP. Here’s the solution:

/** * @snippet       Override & Force Enable Reviews @ WooCommerce Products * @how-to        Get CustomizeWoo.com FREE * @author        Rodolfo Melogli * @compatible    WooCommerce 5 * @donate $9     https://businessbloomer.com/bloomer-armada/ */add_filter( 'comments_open', 'bbloomer_force_enable_reviews', 9999, 2 );function bbloomer_force_enable_reviews( $enable, $post_id ) {	if ( 'product' === get_post_type( $post_id ) ) {		$enable = true;	}	return $enable;}

Here’s the before:

And here’s the after – despite “Enable reviews” is disabled, our snippet overrides that and forces the product to display the reviews tab:

PHP Snippet 2: Force “Sold individually” to All Products

Here things get much easier as WooCommerce gives us a filter hook called “woocommerce_is_sold_individually” (we already covered some case scenarios for that in this post). We can simply override the per-product settings, store-wide, with a 1 liner!

/** * @snippet       Override & Force Sold Individually @ WooCommerce Products * @how-to        Get CustomizeWoo.com FREE * @author        Rodolfo Melogli * @compatible    WooCommerce 5 * @donate $9     https://businessbloomer.com/bloomer-armada/ */add_filter( 'woocommerce_is_sold_individually', '__return_true' );

Here’s the setting screenshot:

And here’s the result on the frontend once the snippet is active:

WooCommerce: Override Single Product Settings e.g. Enable Reviews .