Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Add color for stock status single and variable
- add_action( 'woocommerce_after_shop_loop_item_title', 'woowoo_category_stock', 20 );
- //add_action( 'woocommerce_after_shop_loop_item', 'woowoo_category_stock', 20 );
- function woowoo_category_stock() {
- global $product;
- if ( $product->get_type() == 'simple' ) {
- $stockquantity = $product->get_stock_quantity();
- if ( $stockquantity > 5) {
- echo '<div class="woowoo_green"><i class="fa fa-square" aria-hidden="true" title="auf Lager"></i> - auf Lager</div>';
- }
- elseif ( $stockquantity >= 1 ) {
- echo '<div class="woowoo_yellow"><i class="fa fa-square" aria-hidden="true" title="wenig auf Lager"></i> - nur wenige verfügbar</div>';
- }
- else {
- echo '<div class="woowoo_red"><i class="fa fa-square" aria-hidden="true" title="nicht verfügbar"></i> - nicht verfügbar</div>';
- }
- } else if ( $product->get_type() == 'variable' ) {
- foreach ( $product->get_available_variations() as $key ) {
- foreach ( $key['attributes'] as $attr_name => $attr_value ) {
- if ( $key['max_qty'] > 5 ) {
- echo '<div class="woowoo_green"><i class="fa fa-square" aria-hidden="true" title="auf Lager"></i> ' . $attr_value . ' - jetzt verfügbar</div>';
- }
- elseif ( $key['max_qty'] >= 1 ) {
- echo '<div class="woowoo_yellow"><i class="fa fa-square" aria-hidden="true" title="auf Lager"></i> ' . $attr_value . ' - wenige verfügbar</div>';
- }
- else {
- echo '<div class="woowoo_red"><i class="fa fa-square" aria-hidden="true" title="nicht verfügbar"></i> ' . $attr_value . ' - nicht verfügbar</div>';
- }
- }
- }
- }
- }
- #### CSS for Shop view and product oage with font awesome icon ####
- .woowoo_green { color:#1db214; display:block; text-align:center; font-size:0.85em;clear:both;}
- .woowoo_green:before {font-family: FontAwesome; color:#1db214; content:"\f0c8\0020";}
- .woowoo_yellow { color:#B29815;display:block;text-align:center;font-size:0.85em;clear:both; }
- .woowoo_yellow:before {font-family: FontAwesome; color:#B29815; content:"\f0c8\0020";}
- .woowoo_red { color:#B2141D;display:block;text-align:center;font-size:0.85em;clear:both; }
- .woowoo_red:before {font-family: FontAwesome; color:#B2141D; content:"\f0c8\0020";}
- Shop View -> https://i.imgur.com/3pzSPrl.png
- Product View -> https://i.imgur.com/rCicbrV.png
Add Comment
Please, Sign In to add comment