Home › Forums › WoodMart support forum › New custom label
New custom label
- This topic has 7 replies, 2 voices, and was last updated 3 years, 1 month ago by Aizaz Imtiaz Awan.
-
AuthorPosts
-
October 20, 2021 at 9:04 am #326520
jorodobrevParticipantHi,
I would like to place new custom label to low stock products on shop page.
I have the following code:/** * Add low stock badge. */ function iconic_add_low_stock_badge() { global $product; $manage_stock = $product->get_manage_stock(); $stock = $product->get_stock_quantity(); if ( ! $manage_stock || $stock > 5 ) { return; } ?> <span class="lowstock product-label"><?php _e( 'Last chance!', 'iconic' ); ?></span> <?php } add_action( 'woocommerce_before_shop_loop_item_title', 'iconic_add_low_stock_badge', 9 );
But it doesn’t go to the right placement. Also need css code for this badge with Rectangular shape.
Please advice.
October 20, 2021 at 11:31 am #326576
Aizaz Imtiaz AwanKeymasterHello,
Please add the code to the website and provide the URL of the page. We will check if it is possible to change the position using CSS.
Otherwise, it requires customizations and this is beyond our limitations and support policy.
Best Regards.
October 20, 2021 at 9:00 pm #326680
jorodobrevParticipantCode: /** * Add low stock badge. */ function iconic_add_low_stock_badge() { global $product; $manage_stock = $product->get_manage_stock(); $stock = $product->get_stock_quantity(); if ( ! $manage_stock || $stock > 5 ) { return; } ?> <span class="onsale product-label"><?php _e( 'Последни бройки!', 'iconic' ); ?></span> <?php } add_action( 'woocommerce_before_shop_loop_item_title', 'iconic_add_low_stock_badge', 11 );
Page: https://www.designbunker.eu/shop/
Site language is in bulgarianPlease see attached screenshot: <span class=”onsale product-label”>Последни бройки!</span> should be in <div class=”product-labels labels-rectangular”>…</div>
Attachments:
You must be logged in to view attached files.October 21, 2021 at 7:01 am #326737
Aizaz Imtiaz AwanKeymasterHello,
Please try adding the following Custom CSS in the Global Custom CSS area under Theme Settings >> Custom CSS.
.labels-rectangular span.onsale.product-label { top: 30px !important; left: 0 !important; } .product-label.onsale { position: absolute; top: 5px !important; left: 5px !important; }
Regards.
Xtemos Studios.October 21, 2021 at 8:14 am #326758
jorodobrevParticipantHi,
This should be new type of label for items low of stock. Class: lowstock and the label should go in <div class=”product-labels labels-rectangular”>…</div> in page sourceOctober 21, 2021 at 11:33 am #326800
Aizaz Imtiaz AwanKeymasterHello,
In this case, you need to customize our product’s label functions.
You can find and customize our labels PHP function in the file woodmart/inc/integrations/woocommerce/template-tags.php function is called “
woodmart_product_label
”And customize at your own risk and we could not help you with this as this is beyond our limitations and support policy.
Regards.
Xtemos Studios.October 23, 2021 at 9:02 am #327117
jorodobrevParticipantThanks! If someone needs this I added this code to woodmart/inc/integrations/woocommerce/template-tags.php
global $product; $manage_stock = $product->get_manage_stock(); $stock = $product->get_stock_quantity(); if ( ! $manage_stock || $stock < 5 ) { $output[] = '<span class="lowstock product-label">' . esc_html__( 'Last items!', 'woodmart' ) . '</span>'; }
with the following css:
.labels-rectangular span.lowstock.product-label { top: 30px !important; left: 0 !important; } .product-label.lowstock { top: 5px !important; left: 5px !important; background-color: #fbbc34; } .product-label { word-break: break-word; }
and it works perfectly!
ThanksOctober 23, 2021 at 10:23 am #327124
Aizaz Imtiaz AwanKeymasterHello,
We are Glad that you have managed to solve the issue yourself.
Thanks for sharing the solution here. It would be useful for others who are having the same issue.
Let us know if there’s anything else we can do for you! You can always reach us at any time. We are always here to help you.
Have a wonderful day.
Topic Closed.
Best Regards. -
AuthorPosts
The topic ‘New custom label’ is closed to new replies.
- You must be logged in to create new topics. Login / Register