stock management on product page overwriting woocommerce_get_availability_text
-
hi fahad,
I want to change the “X in stock” and “Out of stock” text that appears on product pages and am using the widely used “woocommerce_get_availability_text” filter below to do so.
I’ve discovered if I turn on Stock Management on Product Page (With or without the dropdown) that it is overwriting the values set in this filter. Is there a way to get your plugin to also apply this filter to the text on the product page?
By the looks of it your plugin is changing this text with javascript, as the values appear correctly then swap just after the page has loaded.add_filter('woocommerce_get_availability_text', 'storefront_change_stock_text', 9999, 2 ); function storefront_change_stock_text ( $availability, $product) { if($product) { $stock = $product->get_stock_quantity(); $_product = wc_get_product( $product ); if ( !$_product->is_in_stock() ) { $availability = __( 'Out of stock online. But check the stores below for in-store pickup availability.', 'woocommerce' ); } if ( $_product->is_in_stock() ) { $availability = __( $stock . ' in stock online for delivery. Pickup availability listed at the stores below.', 'woocommerce' ); } } return $availability; }
Viewing 8 replies - 1 through 8 (of 8 total)
Viewing 8 replies - 1 through 8 (of 8 total)
- The topic ‘stock management on product page overwriting woocommerce_get_availability_text’ is closed to new replies.