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.