This topic has 1 reply, 1 voice, and was last updated 4 minutes ago ago by Alpha111
I hope this message finds you well. I am currently trying to add a custom label for products tagged with “Produits occasion” in my WooCommerce shop using the XStore theme. Despite following various tutorials and implementing code snippets in my child theme’s functions.php file, I have not been able to achieve the desired result.
Here’s what I have tried so far:
I added a function to check for the “Produits occasion” tag and display a custom ribbon using the following code: // Add a custom ribbon for products with the tag “Produits occasion”
function add_custom_ribbon_to_product_image() {
global $product;
// Check if the product has the tag “Produits occasion”
if ( has_term( ‘produits-occasion’, ‘product_tag’, $product->get_id() ) ) {
echo ‘
‘;
}
}
add_action( ‘woocommerce_before_shop_loop_item_title’, ‘add_custom_ribbon_to_product_image’, 10 );
I also added custom CSS to style the ribbon and ensure it appears over the product images:
.custom-product-ribbon {
position: absolute;
top: 10px;
left: 10px;
background-color: #FF5733;
color: #fff;
padding: 5px;
font-size: 14px;
font-weight: bold;
text-transform: uppercase;
z-index: 10;
}
Could you please assist me with the following:
Confirm whether there is a specific hook I should be using with the XStore theme for this functionality.
Provide any guidance on CSS styles that may be conflicting or overriding my custom styles.
Any additional troubleshooting steps I might not have considered.
Thank you for your support. I look forward to your response!
You must be logged in to reply to this topic.Log in/Sign up