• Resolved andi99

    (@andi99)


    Hello again guys! As the title says, in our country a small amount of 0.50 lei was added to each bottle of water, beer, juice and so on. This money can only be returned if you take the bottle back to a recycling container and get your money back. Well, this site has this logo with recycling + the amount of 0.50 lei added on their site to a product. I would like to add the same thing and I would need your help. Thank you!

    And one more thing besides that, how can I add it to appear in stock as it is in this picture of my product?

    Community Verified icon

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Stef

    (@serafinnyc)

    Hello @andi99 for that you could add a hook. This is a hook below with an icon for the FontAwesome library

    function add_custom_message_before_add_to_cart() {
    echo '<i class="fa-solid fa-recycle"></i> <p class="custom-recycle-message">Take this to recycle store to get $0.50 back</p>';
    }
    add_action('woocommerce_before_add_to_cart_button', 'add_custom_message_before_add_to_cart');

    This is a hook without the icon so you can add it via CSS

    function add_custom_message_before_add_to_cart() {
    echo '<span class="recycle-icon"></span><p class="custom-recycle-message">Take this to recycle store to get $0.50 back</p>';
    }
    add_action('woocommerce_before_add_to_cart_button', 'add_custom_message_before_add_to_cart');

    The hook, whichever you choose to add will go inside your functions.php file of your “child theme” do not add this to your parent theme or you will lose it on any future updates

    • This reply was modified 2 months, 3 weeks ago by Stef.
    Thread Starter andi99

    (@andi99)

    Well, I got it but it appears this text just like a description of my product. Also, I don’t want to appear on all the products I have because it appears on all of it, this should appear just for some products like beer, soda, water bottle, not for all of theme. Any suggestions?

    PS: No one of these cods puts the recycle sign.

    Plugin Support Shameem a11n

    (@shameemreza)

    Hi @andi99

    To add the recycling message and icon to specific products only, you can use product categories. First, categorize your products into those that require the recycling message (like beer, soda, and water bottles) and those that don’t. Then, modify the hook to check if the product belongs to the recycling category before displaying the message.

    Although writing or providing custom code is not within the scope of our support policy, here’s an example:

    function add_custom_message_before_add_to_cart() {
        global $product;
        if ( has_term( 'recycling', 'product_cat', $product->id ) ) {
        echo 'Take this to recycle store to get $0.50 back';
        }
    }
    add_action('woocommerce_before_add_to_cart_button', 'add_custom_message_before_add_to_cart');

    Here, “recycling” is the product category slug that should display the recycling message. Replace it with the actual slug of your category.

    If you are still having problems, we recommend asking development questions on the #developers channel of the WooCommerce Community Slack. Many of our developers hang out there and will be able to offer insights into your question. You can also seek help from the following:

    No one of these cods puts the recycle sign.

    Please make sure the FontAwesome library is correctly loaded on your site. If it’s not loaded, the icon will not display. In that case, you can use the Dashicons.

    how can I add it to appear in stock as it is in this picture of my product?

    You can add it by going to the product’s WooCommerce settings, under the “Inventory” tab. There, you can manage stock levels and display the stock status on the product page.

    I wish I could help more, but hopefully, this gets you going in the right direction to get the job done.

    Plugin Support Shameem a11n

    (@shameemreza)

    Hi @andi99

    We’ve not heard back from you in a while, so I’m marking this thread as resolved. Hopefully, you were able to find a solution to your problem!

    If you have further questions, please feel free to open a new topic.

    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.