I state that I am not an expert! My function modifies the visibility of the product based on the presence of the price. It works well with simple products, but not with products that have variables. To be more precise, the visibility of the variable is changed in the variable product, but not the parent product.
My question is: how do I, in case of variables, set the visibility filter on the parent product? This is my current code:
if ($listinoWeb == "")
{
delete_post_meta($product_id, 'wwpp_product_wholesale_visibility_filter', 'all');
add_post_meta($product_id, 'wwpp_product_wholesale_visibility_filter', 'wholesale_customer', TRUE);
}
else
{
add_post_meta($product_id, 'wwpp_product_wholesale_visibility_filter', 'all', TRUE);
delete_post_meta($product_id, 'wwpp_product_wholesale_visibility_filter', 'wholesale_customer');
}
You can call the
get_parent_id()
function on the product object. Which will return0
if you call it on a simple/parent product. So you can do something like this:This way you're sure the
$product_id
variable always contains the parent id.