Home Forums WoodMart support forum New custom label

New custom label

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #326520

    jorodobrev
    Participant

    Hi,
    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.

    #326576

    Hello,

    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.

    #326680

    jorodobrev
    Participant
    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="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 bulgarian

    Please 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.
    #326737

    Hello,

    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.

    #326758

    jorodobrev
    Participant

    Hi,
    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 source

    #326800

    Hello,

    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.

    #327117

    jorodobrev
    Participant

    Thanks! 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!
    Thanks

    #327124

    Hello,

    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.

Viewing 8 posts - 1 through 8 (of 8 total)

The topic ‘New custom label’ is closed to new replies.