PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, May 9, 2022

[FIXED] How can i get product visibility in WooCommerce loop?

 May 09, 2022     methods, php, product, woocommerce, wordpress     No comments   

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing