How to Change WooCommerce Product Visibility Options

WooCommerce Product VisibilityDo you want to change the visibility of a product in your WooCommerce store? You might want to change the visibility of a single product in your WooCommerce store, but you do not know how to go about it. This post aims to show you exactly how to do that.

WooCommerce Product Visibility

There are scenarios you may need to hide a product from your WooCommerce store. Some of them include:

  1. If products are only available to certain customers, the products need to be hidden from the public.
  2. If products are no longer sold but may be sold again in the future.
  3. If you offer service-based products, they require to be manually added to a sales representative quote.

There are many other scenarios, but these stand out. To start, I will share how to hide a single WooCommerce product from the front end using the built-in WooCommerce and WordPress functionality. Moreover, I will share how you can hide hidden products from WooCommerce cart, checkout, order, and emails.

Steps to Hide a WooCommerce Product (Single Product)

  1. Log into your WordPress site and access the Dashboard as the admin user.
  2. From the Dashboard menu, click on Products and select the product you would like to hide from the site.
  3. Click on the Product title and go to the edit page, as shown below:click on product title
  4. On the right-hand side, you will see the familiar “Publish” meta box. It allows you to set publishing options and publish your posts, products, or pages. There is an option there called “Catalog visibility.” Click on the Edit link next to it. You will be presented with a list of options for the visibility of the Product on the front end.
  5. Select the Hidden optionset a hidden product
  6. Click on the Update button, and the product will completely disappear from the front end of your WooCommerce Store.

However, it is worth mentioning that even though hidden products do not show on the shop and category pages, they appear on the cart if they are added to the cart “programmatically.” Therefore, we need to hide hidden products on the cart, checkout, order received, and emails. This is a challenging task, but as usual, I have a solution for this.

Steps to Hide Hidden Products from WooCommerce Cart, Checkout, Order, and Emails

Here are the steps that you need to follow:

  1. Log into your WordPress site and access the Dashboard as the admin user.
  2. From the Dashboard menu, click on Appearance Menu > Theme Editor Menu. When the Theme Editor page is opened, look for the theme functions file to add the function to hide products from the WooCommerce cart, checkout, order received, and emails.
  3. Add the following code to the function.php file:
/**

 * Hide Hidden Products from Cart, Checkout, Order - WooCommerce

  */

  add_filter( 'woocommerce_cart_item_visible', 'njengah_hide_hidden_product_from_cart' , 10, 3 );

add_filter( 'woocommerce_widget_cart_item_visible', 'njengah_hide_hidden_product_from_cart', 10, 3 );

add_filter( 'woocommerce_checkout_cart_item_visible', 'njengah_hide_hidden_product_from_cart', 10, 3 );

add_filter( 'woocommerce_order_item_visible', 'njengah_hide_hidden_product_from_order_woo333', 10, 2 );

   function njengah_hide_hidden_product_from_cart( $visible, $cart_item, $cart_item_key ) {

    $product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );

    if ( $product->get_catalog_visibility() == 'hidden' ) {

        $visible = false;

    }

    return $visible;

}

   function njengah_hide_hidden_product_from_order_woo333( $visible, $order_item ) {

    $product = $order_item->get_product();

    if ( $product->get_catalog_visibility() == 'hidden' ) {

        $visible = false;

    }

    return $visible;

}

 

  1. Remember to save the changes you make.

Conclusion

In summary, this post illustrates how you can change product visibility in your WooCommerce store. Additionally, I have highlighted some of the scenarios that might push you to hide a product from your store. However, you need to know that hiding the product is not enough, as it can be added to the cart programmatically. I have shared a PHP snippet that you can use to hide the product from the cart, checkout, order received, and emails.

Similar Articles

  1. How to Hide Product Prices Based on User Role Storefront

 

Comments are closed.