Guest User

Untitled

a guest
Jan 6th, 2019
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. // Add color for stock status single and variable
  2. add_action( 'woocommerce_after_shop_loop_item_title', 'woowoo_category_stock', 20 );
  3. //add_action( 'woocommerce_after_shop_loop_item', 'woowoo_category_stock', 20 );
  4.  
  5. function woowoo_category_stock() {
  6. global $product;
  7. if ( $product->get_type() == 'simple' ) {
  8. $stockquantity = $product->get_stock_quantity();
  9. if ( $stockquantity > 5) {
  10. echo '<div class="woowoo_green"><i class="fa fa-square" aria-hidden="true" title="auf Lager"></i> - auf Lager</div>';
  11. }
  12. elseif ( $stockquantity >= 1 ) {
  13. echo '<div class="woowoo_yellow"><i class="fa fa-square" aria-hidden="true" title="wenig auf Lager"></i> - nur wenige verfügbar</div>';
  14. }
  15. else {
  16. echo '<div class="woowoo_red"><i class="fa fa-square" aria-hidden="true" title="nicht verfügbar"></i> - nicht verfügbar</div>';
  17. }
  18. } else if ( $product->get_type() == 'variable' ) {
  19. foreach ( $product->get_available_variations() as $key ) {
  20. foreach ( $key['attributes'] as $attr_name => $attr_value ) {
  21. if ( $key['max_qty'] > 5 ) {
  22. echo '<div class="woowoo_green"><i class="fa fa-square" aria-hidden="true" title="auf Lager"></i> ' . $attr_value . ' - jetzt verfügbar</div>';
  23. }
  24. elseif ( $key['max_qty'] >= 1 ) {
  25. echo '<div class="woowoo_yellow"><i class="fa fa-square" aria-hidden="true" title="auf Lager"></i> ' . $attr_value . ' - wenige verfügbar</div>';
  26. }
  27. else {
  28. echo '<div class="woowoo_red"><i class="fa fa-square" aria-hidden="true" title="nicht verfügbar"></i> ' . $attr_value . ' - nicht verfügbar</div>';
  29. }
  30. }
  31.  
  32. }
  33. }
  34. }
  35.  
  36. #### CSS for Shop view and product oage with font awesome icon ####
  37. .woowoo_green { color:#1db214; display:block; text-align:center; font-size:0.85em;clear:both;}
  38. .woowoo_green:before {font-family: FontAwesome; color:#1db214; content:"\f0c8\0020";}
  39. .woowoo_yellow { color:#B29815;display:block;text-align:center;font-size:0.85em;clear:both; }
  40. .woowoo_yellow:before {font-family: FontAwesome; color:#B29815; content:"\f0c8\0020";}
  41. .woowoo_red { color:#B2141D;display:block;text-align:center;font-size:0.85em;clear:both; }
  42. .woowoo_red:before {font-family: FontAwesome; color:#B2141D; content:"\f0c8\0020";}
  43.  
  44. Shop View -> https://i.imgur.com/3pzSPrl.png
  45. Product View -> https://i.imgur.com/rCicbrV.png
Add Comment
Please, Sign In to add comment