Ask Your Question
4

How can the div of a WooCommerce product page be hidden if the product is available in stock?

asked 2022-02-20 11:00:00 +0000

huitzilopochtli gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-09-02 08:00:00 +0000

woof gravatar image

To hide the div of a WooCommerce product page if the product is available in stock, you can use the following code:

addaction( 'woocommercesingleproductsummary', 'hidedivifinstock', 5 ); function hidedivifinstock() { global $product; if( $product->isinstock() ) { echo '<style>.div-class-name{ display: none !important; }</style>'; } }

This code will add an action to the WooCommerce single product summary, and it will check if the product is in stock. If the product is in stock, the code will echo a style tag with a CSS rule that will hide the div with the class name "div-class-name". Replace "div-class-name" with the actual class name of the div you want to hide.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-02-20 11:00:00 +0000

Seen: 10 times

Last updated: Sep 02 '22