I want to add a div with a class inside of a existing element in WordPress/Woocommerce. I want to make the sale price more pretty :) Let's start with what I have now: enter image description here
Code:
<ins>
<span class="woocommerce-Price-amount amount">
<bdi>
<span class="woocommerce-Price-currencySymbol">$</span>200.00
</bdi>
</span>
</ins>
And this is what I am trying to achieve: enter image description here
Code:
<ins>
<span class="woocommerce-Price-amount amount">
<div class="vh-badge-ears"></div>
<bdi>
<span class="woocommerce-Price-currencySymbol">$</span>200.00
</bdi>
</span>
</ins>
the closest I have come to is adding this code to my functions.php:
function bd_sale_price_html( $price, $product ) {
if ( $product->is_on_sale() ) :
$return_string = str_replace( '<ins><span class="woocommerce-Price-amount amount">', '<ins><span class="woocommerce-Price-amount amount"><div class="vh-badge-ears"></div>', $price);
return $return_string;
else :
return $price;
endif;
}
add_filter( 'woocommerce_get_price_html', 'bd_sale_price_html', 100, 2 );
But by using this code it looks like this: enter image description here
I hope someone here could help me out.
Kind regards!
divis block element and should not be insidespan. Validate your HTML with w3 validator.::beforefor this instead?.price > ins > .amount { position: relative; background-color: #28a745; color: #ffffff; padding-left: 5px; padding-right: 5px; border-radius: 5px; } .price > ins > .amount::before { position: absolute; background-image: url(./ears.svg); background-size: contain; background-repeat: no-repeat; background-position: center; width: 100%; height: 100%; top: -80%; }::beforewill give you one free virtual DOM element that you can do things with, just make sure to give itcontentof some sort, which can just be empty: codepen.io/cjhaas/pen/yLqaqbZ