daily pastebin goal
78%
SHARE
TWEET

WooCommerce - Show delivery time based on stoc

lorro Nov 20th, 2016 22 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.   // WooCommerce - Show delivery time based on in or out of stock
  3.   // usage: [delivery in_stock="2" no_stock="10-12"]
  4.   // works only on product pages
  5.   // code goes in functions.php for your child theme
  6.   add_shortcode('delivery', 'delivery');
  7.   function delivery( $atts ) {
  8.     global $product;
  9.     $stock = $product->stock;
  10.     if ($stock) {
  11.       $days = $atts['in_stock'];
  12.       echo '<p class="delivery">In stock: Ships within '.$days.' days</p>';
  13.     } else {
  14.       $days = $atts['no_stock'];
  15.       echo '<p class="delivery">Out of stock: Ships within '.$days.' days</p>';
  16.     }
  17.   }
RAW Paste Data
Top