• Resolved mikmikmik

    (@mikmikmik)


    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)
  • Plugin Author Fahad Mahmood

    (@fahadmahmood)

    @mikmikmik implemented, thank you. Please wait for a few hours as I have to add a few more things then will release the new version.

    Thread Starter mikmikmik

    (@mikmikmik)

    Thanks fahad!
    There’s a few edges cases that can affect that output, like if backorders are turned on, and if stock management is turned on etc, which you might want to add. But given you’re now applying the filter people can also easily override it in their theme functions.php file.

    Thread Starter mikmikmik

    (@mikmikmik)

    Also I think the default messages should just be “Out of stock” and “x in stock”, not the long protracted explanation of my specific use case! ??

    Plugin Author Fahad Mahmood

    (@fahadmahmood)

    @mikmikmik I have just made the changes to Out of stock string and also reduced the priority to number 9. I hope it would be understood for the developers to keep the priority above number 10 to override. Thank you for shedding light on this aspect.

    Thread Starter mikmikmik

    (@mikmikmik)

    hi fahad,
    i thought this one was resolved, but have discovered the stock value is being overridden if the user is logged into wordpress/woocommerce.

    logged out users see the overridden value.
    logged in users see the stock value your plugin sets (0) no matter how hard i try to override it with higher priority functions. weirdly it’s just the stock value itself, not the text that i’m overriding around it.

    have confirmed this by being logged in and toggling the activation of your plugin

    cheers,
    mik

    Plugin Author Fahad Mahmood

    (@fahadmahmood)

    Dear Mik,

    functions.php file, line 745 and 746, try commenting these lines and let me know about the outcomes. Also please schedule a meeting so we can troubleshoot it together.

    	add_filter( 'woocommerce_get_availability_text', 'slw_change_stock_text', 9, 2 );
    	add_filter( 'woocommerce_get_availability', 'slw_filter_woocommerce_get_availability', 9, 2 ); 	

    Thanks,
    Fahad

    Thread Starter mikmikmik

    (@mikmikmik)

    Ah just discovered it’s only happening if the “Stock management on product page” option is set to “No”. Setting that option to “Without locations dropdown” or “With locations dropdown” corrects the issue.

    Plugin Author Fahad Mahmood

    (@fahadmahmood)

    No means, do not use our custom field. I am continuously improving this plugin and soon you will the settings area more meaningful and easy to understand. Thank you so much for the feedback.

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.