Woocommerce – Setting a product to hidden within a plugin

I’m having issues trying to hide a product from public view. I’m creating a product then I would like to assign it as hidden.

register_activation_hook( __FILE__, 'hide_product' );
function hide_product()  
{
update_post_meta($post_id, '_visibility', 'hidden' );
}

Following these two links and they show the following code but that doesn’t work either. I’ve tried hardcoding in an ID and also the ID thats created after the product is created.

update_post_meta( $post_id, '_visibility', 'visible' );

http://jafty.com/blog/programatically-create-woocommerce-products-with-variations/
http://lukasznowicki.info/insert-new-woocommerce-product-programmatically/

Read more here: Woocommerce – Setting a product to hidden within a plugin

Leave a Reply

Your email address will not be published. Required fields are marked *