I want to learn so i need to understand what’s happening with the following
code and why it’s not working as i want it to do

I want to change the the price class to set a custom color(only product page/shop) and add custom meta text before and after the price

adding custom text works but it doesn’t replace the code instead it leaves

empty and adds another box

function change_price_display( $price ) {
    $new_price .= "<div class='box'><div class='before-price'>". get_post_meta(get_the_ID(),'_custom_product_choice', true) ."</div>". $price ."<div class='after-price'>".get_post_meta(get_the_ID(),'_custom_product_weight', true)."</div></div>";
    return $new_price;
add_filter( 'woocommerce_get_price_html', 'change_price_display', 10, 2);

https://i.stack.imgur.com/bc11k.png (html code output)

https://i.stack.imgur.com/w6Lcs.png (what i want to create)

I hope anyone can help me with this

Thanks in advance Sander

Read more here: change class, add custom meta to woocommerce_get_price_html


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: