Before you ask please READ THIS

Replacing "Out of Stock" ribbon with "Sold" badge for specific categories

Hello Air,

I have been trying to replace the "Out of Stock" ribbon with "Sold" on the product list/single product pages, but I can't seem to be able to do it successfully. I wanted to do it for a specific category category only as we are selling one-of-a-kind pieces in this category. I've tried different snippets that I found online; however, no luck.

Ideally, it would be nice suppress the "Out of Stock" ribbon and display a "Sold" badge instead, but if it's too complicated the one described above would work, too.

Wondering if you can help me replace the relevant code in the theme?

Thank you in advance!

Comments

  • AirAir
    edited September 2020 Posts: 10,970
    Hey LazyDiver:-)

    OK, let us start with a general solution first:

    You can rename this ribbon in rife\advance\utilities\woocommerce.php line ~325
    Change:
    $html .= '<span class="ribbon out-of-stock"><em>'.esc_html__( 'Out of stock', 'rife' ).'</em></span>';
    to
    $html .= '<span class="ribbon out-of-stock"><em>'.esc_html__( 'Sold', 'rife' ).'</em></span>';

    If you want to remove this ribbon, then you can just remove above mentioned line, or comment it out, like this(double slash in front):
    //$html .= '<span class="ribbon out-of-stock"><em>'.esc_html__( 'Out of stock', 'rife' ).'</em></span>';

    If you want to change/remove it only for a particular category use such code instead:
    if(!has_term( 'art-sale', 'product_cat') ){
                $html .= '<span class="ribbon out-of-stock"><em>'.esc_html__( 'Out of stock', 'rife' ).'</em></span>';
    }
    Hope that helps.

    With kind regards.
    Post edited by Air on
  • Hi Air,

    Thank you for the above.

    Unfortunately, it didn't work for me... I placed the file in the child theme folder as I didn't want the code to be replaced when the theme gets updated. Also, in the file it was 'rife' instead of 'fatmoon', so that's what I used.

    I wonder if there's something that I did wrong?

    Thank you.
  • AirAir
    Posts: 10,970
    LazyDiver said: Also, in the file it was 'rife' instead of 'fatmoon', so that's what I used.
    Sure my bad, I am editing my previous post.
    LazyDiver said: I wonder if there's something that I did wrong?
    No clue. I have tested those changes before posting and they work fine.

    Try editing the main theme. If it will work fine, then move those changes to the child theme. Otherwise, there are too many "moving parts "to know where the fail happened.

    With kind regards.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!