New Landing How can we help? Atelier Custom badge on Product thumb if Attribute present

Viewing 6 posts - 1 through 6 (of 6 total)
  • Posted in: Atelier
  • #186403
    rayjonnes
    Member
    Post count: 10

    Hi,

    I got a catalog of products and I got Attribute “In stock”  and variants Yes and No. So half of goods are with attibute “In stock-Yes” and how to make a custom badge (or override existing OUT OF STOCK for ex) to show it product got selected Yes on Attribute “In stock” the image got the badge “ITEM IN STOCK!!!” ?

    #186429
    Rui Guerreiro – SUPPORT
    Keymaster
    Post count: 25779

    Hi,

    The code below should work using the default stock fields in Woocommerce(not sure why you created that new attribute)

    
    add_filter( 'woocommerce_get_availability', 'custom_get_availability', 1, 2);
    
    function custom_get_availability( $availability, $_product ) {
      global $product;
      $stock = $product->get_total_stock();
    
      if ( $_product->is_in_stock() ) $availability['availability'] = '<div>My html code for the icon In Stock</div>';
      
    
      return $availability;
    }

    Add it to the functions.php of the child theme.

    -Rui

    #186441
    rayjonnes
    Member
    Post count: 10

    And is any way to do it with Attribute not default Availability?

    #186567
    rayjonnes
    Member
    Post count: 10

    And btw I did this Attribute to make a Filter in sidebar to select Availible items to filter out

    #186570
    rayjonnes
    Member
    Post count: 10

    And your suggested code:
    add_filter( ‘woocommerce_get_availability’, ‘custom_get_availability’, 1, 2);

    function custom_get_availability( $availability, $_product ) {
    global $product;
    $stock = $product->get_total_stock();

    if ( $_product->is_in_stock() ) $availability[‘availability’] = ‘<div>My html code for the icon In Stock</div>’;

    return $availability;
    }

     

    it just gives a “<div>My html code for the icon In Stock</div>” text (or code) in Product Description area. And I was talking about bade on the product image – like a “OUT OF STOCK” or “SALE!” badges. How to do this badges?

    For example is product is availible – we got IN STOCK badge on product image, and if product is not in stock – there is no badge on image (now there is OUT OF STOCK badge and I dont need it in that case if we got IN STOCK badge)

    #186969
    Rui Guerreiro – SUPPORT
    Keymaster
    Post count: 25779

    Hi,

    Forget about that previous code.
    You can use your attribute in the filter and at the same time use the stock to appear the badge.

    This is our current badge we can change it.
    https://www.dropbox.com/s/dz18a0okz17w4bn/sold_out.png?dl=0

    What text/colors you would like to display?

    -Rui

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

You must be logged in and have valid license to reply to this topic.

License required for one of the following items
Login and Registration Log in · Register