Change (amount) "In Stock" text on PRODUCT VARIATIONS

  • Unknown's avatar

    I have adapted WooCommerce to sell tables at an event I am hosting. The event has 20 different tables (categorised by “profession”) priced differently for each.

    Because of this I have setup a product for the event called “Bournemouth Event” and then setup product variations such as “Photographer Table”, “Swimming School Table” and so on with different prices, stock levels and amount of tables for each.

    All works as it should apart from 1 minor detail. On the live site when you click a variation it says (for instance) “Photographers Table – 5 in stock”.

    I want this to say “Photographers Table – 5 tables available”

    I have tried everything I can think of but the 2 best solutions (code in functions.php) do not work as they should.

    The first code I tried almost works – unfortunately though this code totalled all of the tables available so looked like “Photographers Table – 20 in stock”

    This is the code for the first code:

    // WooCommerce Stock message
    add_filter( 'woocommerce_get_availability', 'custom_get_availability', 1, 2);
    
    function custom_get_availability( $availability, $_product ) {
      global $product;
      $stock = $product->get_total_stock();
    
      if ( $_product->is_in_stock() ) $availability['availability'] = __($stock . ' tables available', 'woocommerce');
      if ( !$_product->is_in_stock() ) $availability['availability'] = __('Sorry – all tables of this business type have been booked', 'woocommerce');
    
      return $availability;
    }

    ….. all other bits of code do little but remove the number all together (so with a result such as “in stock”)

    Is there anyone out there who knows how to solve the above? I know it must be very similar to the first bit of code – with a possible change to the $stock = $product->get_total_stock() part but am going around in circles!

    Thanks in advance, any help would be greatly appreciated!

    WooCommerce

  • Unknown's avatar

    Hi there,
    You are posting to the wrong support forum. Woo Commerce can be run on self hosted WordPress.ORG installs only. You cannot run woo commerce on any WordPress.COM hosted blog and the latter are the only blogs we support here.

    Learn about the differences here. http://support.wordpress.com/com-vs-org/

    WordPress.COM and WordPress.ORG are completely separate and have different logins, features, run different versions of some themes with the same names, and have separate documentation and support forums.

    If you don’t have a username account at WordPress.ORG click http://wordpress.org/support/ and register one on the top right hand corner of the page that opens, so you can post to the Theme support forums there.

    Resetting your WordPress.ORG password http://codex.wordpress.org/Resetting_Your_Password

    WordPress.org support docs are at https://codex.wordpress.org/Main_Pag

  • The topic ‘Change (amount) "In Stock" text on PRODUCT VARIATIONS’ is closed to new replies.