• helmi

    (@helmi)


    I really wonder this isn’t implemented in WooCommerce and also wonder that there doesn’t seem to be any plugin or other solution. Maybe I’m wrong? This is why I’m posting it here.

    What I want to achieve is to update the Delivery Time estimate (For me the time until the product ships from the seller) based on the Inventory status.

    Example:

    in stock: Ships within 2 days
    out of stock: Ships within 10-12 days

    This should be based on the product so hacking it via the theme template files would be an ugly solution.

    Any ideas?

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Depends, would this be the same for all products – you could use a hook on the single product page, or on a per-product basis – you could use a custom shortcode:
    [delivery product_id=”99″ in_stock=”2″ no_stock=”10″]

    “Delivery period” isn’t a property of the product object. Do you store this data somewhere, in a custom field perhaps.

    Thread Starter helmi

    (@helmi)

    Well that’s why I wrote…

    This should be based on the product so hacking it via the theme template files would be an ugly solution.

    so yes, it should be on a per-product-base like it is now with the delivery time. It should just be different for “in stock” or “out of stock”.

    Works for me. Your experience may differ!

    
    <?php
      // show delivery time based on in or out of stock
      // usage: [delivery in_stock="2" no_stock="10-12"]
      add_shortcode('delivery', 'delivery');
      function delivery( $atts ) {
        global $product;
        $stock = $product->stock;
        if ($stock) {
          $days = $atts['in_stock'];
          echo '<p class="delivery">In stock: Ships within '.$days.' days</p>';
        } else {
          $days = $atts['no_stock'];
          echo '<p class="delivery">Out of stock: Ships within '.$days.' days</p>';
        }
      }
    

    Works on product pages only. A stock amount must be set – just “In stock” is not sufficient. Code goes in functions.php for your child theme. Shortcode can be used in the product description.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to update Delivery Time based on stock status’ is closed to new replies.