Set Catalog visibility hidden woo-commerce

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

Like its mentioned here :

Read More

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

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

Related posts

2 comments

  1. 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"
    
  2. 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)

Comments are closed.