Code Tidy - Pastebin

New     Fork     Embed     View raw     View parent     Report

WPeC-display Inventory count - text

Embed

You can embed this paste into a blog or website with this code:

<iframe class="codetidy" type="text/html" width="100%" src="http://codetidy.com/paste/embed/2890" frameborder="0"></iframe>

Add comment

Captcha
  1. In the wpsc-single_product.php file I replaced line #151?
  2.  ?
  3. <div id="stock_display_<?php echo wpsc_the_product_id(); ?>" class="in_stock"><?php _e('Product in stock', 'wpsc'); ?></div>?
  4.  ?
  5.  ?
  6. To this:?
  7.  ?
  8. <div id="stock_display_<?php echo wpsc_the_product_id(); ?>" class="in_stock">?
  9. <?php function wpsc_variations_stock_remaining($product_id){?
  10.     global $wpdb;?
  11.     return $wpdb->get_var('?
  12.         SELECT ?
  13.             sum(`pm`.`meta_value`) ?
  14.         FROM ?
  15.             `' . $wpdb->postmeta . '` `pm` ?
  16.         JOIN ?
  17.             `' . $wpdb->posts . '` `p` ?
  18.             ON ?
  19.             `pm`.`post_id` = `p`.`id` ?
  20.         WHERE ?
  21.             `p`.`post_type`= "wpsc-product"?
  22.             AND?
  23.             `p`.`post_parent` = ' . $product_id . '?
  24.             AND?
  25.             `pm`.`meta_key` = "_wpsc_stock"?
  26.     ');?
  27. }?
  28.  ?
  29. ?>?
  30.  ?
  31. <?php// Added if statement to message will appear at 3 or less items;?>?
  32. <?php ?
  33. $stock = get_post_meta( $post->ID, '_wpsc_stock', true );?
  34. $remaining_quantity = wpsc_variations_stock_remaining( $post->ID );?
  35.  ?
  36. if ($stock <= "3" && $stock !=0){?
  37.       _e('Only ', 'wpsc'); echo $stock;echo $remaining_quantity; _e(' left in stock. Order today!', 'wpsc');?
  38. } ?
  39. ;?>?
  40.  ?
  41. this covers both stock for items without variations and items with variations (combining the number for all variation stock). However it does show 0 if you have variations without any stock set.?
  42.  ?
  43. Please let me know if anyone who would know a better way or cleaner code to accomplish this. And possibly any alternative if statements to not show this for items without variation stock set.?
  44.  ?
  45. Aside from this you can easily change the wording of the message, if you don't want to display the actual inventory number.?
  46. Change:?
  47. <code><?php _e('Product in stock', 'wpsc'); ?></code>?
  48. to:?
  49. <code><?php _e('Your Message Here', 'wpsc'); ?></code>?
© 2011 Code Tidy