Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Catalog visibility hidden woo-commerce

Tags:

wordpress

How to set Catalog visibility hidden in woo-commerce WordPress programmatically?

Like its mentioned here :

https://docs.woothemes.com/document/catalog-visibility-options/

But i can't find any hook or hack, that how to do it in PHP.

like image 687
daniyalahmad Avatar asked Apr 09 '16 20:04

daniyalahmad


People also ask

What is visibility in catalog in WooCommerce?

Catalog Visibility Options transforms your WooCommerce store into a catalog by giving you the option to disable all eCommerce functionality. This includes changing the “Add to Cart” and “Buy Now” buttons as well as disabling the regular checkout and cart processes.

How do I hide categories from being displayed on shop page WooCommerce?

From the admin panel, go to WooCommerce > Product Visibility > Global visibility tab and select the product and category you want to hide.

What is private visibility on WooCommerce?

A private product is one that is not visible to the public on your WooCommerce store. By default, all products in WooCommerce are public, meaning they can be seen and purchased by anyone.


2 Answers

I have tried doing this for some days, and there is nothing about it online so I read the woocommerce documentation and discovered that in woocommerce 3.x.x the visibility is a taxonomy called "product_visibility".

To achieve that you should set taxonomy terms, for example:

//Set product hidden: 
$terms = array( 'exclude-from-catalog', 'exclude-from-search' );
wp_set_object_terms( $post_id, $terms, 'product_visibility' );

//Set product visible in catalog:
$terms = 'exclude-from-search';
wp_set_object_terms( $post_id, $terms, 'product_visibility' );

//Set product visible in search:
$terms = 'exclude-from-catalog';
wp_set_object_terms( $post_id, $terms, 'product_visibility' );

All possible taxonomy terms:

"exclude-from-catalog"
"exclude-from-search"
"featured"
"outofstock"
like image 92
Daniel Ramirez Avatar answered Sep 21 '22 20:09

Daniel Ramirez


The visibility is set in the custom field _visibility. You can change it with update_post_meta():

update_post_meta( $product_id, '_visibility', '_visibility_hidden' );

Possible values:

  • visible (Catalog & Search)
  • catalog (Catalog only)
  • search (Search only)
  • hidden (nowhere)
like image 23
Andy Tschiersch Avatar answered Sep 20 '22 20:09

Andy Tschiersch