Issue
How can i get the value of a product visibility ?
I would like to set a conditional display in a loop, based on product visibility if hidden.
Something like :
if($my_product is hidden) {
}
Solution
You can simply use the WC_Product
method is_visible()
on the WC_Product
Object like:
global $product;
// Be sure to get the WC_Product instance object
if( ! is_a( $product, 'WC_Product' ) ) {
$product = wc_get_product( get_the_id() );
}
// Check product visibility
if( ! $product->is_visible() ) {
// Not visible
} else {
// Visible
}
It should work.
Answered By - LoicTheAztec Answer Checked By - Mildred Charles (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.