Hide query button when product is in stock
P粉860370921
P粉860370921 2023-09-02 17:30:31
0
1
401
<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>
P粉860370921
P粉860370921

reply all(1)
P粉555696738

What you are looking for is this:

add_action( 'woocommerce_single_product_summary', 'remove_enquiry_button_if_out_of_stock', 30 );
function remove_enquiry_button_if_out_of_stock() {
    global $product;
    if ( ! $product->is_in_stock() ) {
        remove_action( 'woocommerce_single_product_summary', array( Product_Enquiry_For_Woocommerce::instance(), 'enquiry_button' ), 25 );
    }
}

Or via CSS:

.product.out-of-stock .pe-show-enq-modal {
    display: none;
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!