Hide query button when product is in stock
P粉860370921
2023-09-02 17:30:31
<p>How to hide specific buttons based on a product's stock status? </p>
<p>The plugin is creating this class: </p>
<pre class="brush:php;toolbar:false;">function wdm_pefree_init() {
// phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
if ( ! class_exists( 'Product_Enquiry_For_Woocommerce', false ) ) {
include_once WDM_PE_PLUGIN_PATH . '/includes/class-product-enquiry-for-woocommerce.php';
}
Product_Enquiry_For_Woocommerce::instance();
}</pre>
<p>I only want to display this button on a single product page for each product that is out of stock, but I can't get my code to work. </p>
<p>I'm not very familiar with PHP, so I tried adjusting some other code in the Functions.php file without success. </p>
<p>Any help would be great, thank you! </p>
<p>I tried this code: </p>
<pre class="brush:php;toolbar:false;">add_filter('woocommerce_get_availability', 'wcs_custom_get_availability', 1, 2);
function wcs_custom_get_availability($availability, $_product) {
// Remove Inquiry Button
if (!$_product->is_in_stock()) {
remove_action('Product_Enquiry_For_Woocommerce');
}
return $availability;
}</pre>
<p>I also see that the css class of the button is .pe-show-enq-modal, but I cannot enforce the condition "Visibility: Hidden" which only applies to out-of-stock products. </p>
What you are looking for is this:
Or via CSS: