• Hi, thanks for the plugin. It’s been a great help to our project.

    So, with our project having unique items with only one item in stock each, with Cart Stock Reducer we are able to reserve items in users baskets for 10 minutes.

    Our issue is that we are required to display items that are sold. Therefore we display all items, even ones that are out of stock, and have some code to change the standard “Read More’ text to “Sold” for both the shop and product pages. That code is:

    /** Change out of stock text
     */
    function change_text_soldout ( $text, $product) { 
        if ( !$product->is_in_stock() ) {
            $text = __('Sold', 'woocommerce'); 
        } 
        return $text; 
    }
    add_filter('woocommerce_get_availability_text', 'change_text_soldout', 10, 2 );
    
    /** Replace Read More with Out of Stock
     */
    add_filter('gettext',  'wps_translate_words_array');
    add_filter('ngettext',  'wps_translate_words_array');
     
    function wps_translate_words_array( $translated ) {
      $words = array(
        // 'word to translate' = > 'translation'
        'Read More' => 'Sold',  
      );
      $translated = str_ireplace(array_keys($words), $words, $translated);
      return $translated;
    }

    However, when someone reserves an item in their basket, this reduces the stock to 0 and therefore the shop page displays “SOLD”, which is incorrect. Is it possible to hook the ‘virtual’ stock rather than the ‘actual’ stock. So that ‘SOLD’ only appears for items with an actual stock of 0 ?

    Any guidance would be great. Thank you.

    Jim

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author James Golovich

    (@jamesgol)

    There’s a few ways to do this. If you want to retrieve the actual stock quantity you can do:

    
    $csr = WC()->integrations->get_integration('woocommerce-cart-stock-reducer');
    $actual_stock = $csr->get_actual_stock_available( $product );
    

    If you want your function to always receive the actual stock without caring about if the CSR plugin is installed/activated you can add a filter to add your function to a list. Look at the ‘wc_csr_whitelist_get_stock_status’ and ‘wc_csr_whitelist_get_stock_quantity’ filters in the plugin (not really documented other than in the commit logs https://github.com/jamesgol/woocommerce-cart-stock-reducer/commit/30f64a3e6cd2a517ba80104240eb186c383653cf)

    Thread Starter arubac

    (@arubac)

    Can anyone advise how I can implement this into the code above in order to function correctly?

    Any help appreciated. Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Changing text for reserved products’ is closed to new replies.