Adding custom text to the variation price in Wooco

2019-07-29 05:32发布

I thought this would have been easy, but I am stuck. All I am trying to do is add the word each after the variation price on a product page. The solution I have found adds it on the category page and in two places on the product page.

The code is:

 /*  Adds a text Each - after price */
function change_product_price( $price ) {
    $price .= ' each';
    return $price;
}
add_filter( 'woocommerce_get_price_html', 'change_product_price' );

enter image description here

From the picture above, I only need the each added to the price above the add to cart button, but not the other pacles like the crossed out section in the photo above.

Thank you for any guidance you can provide.

1条回答
该账号已被封号
2楼-- · 2019-07-29 06:09

The following code will add a suffix to the product variations price:

add_filter('woocommerce_available_variation', 'variation_price_custom_suffix', 10, 3 );
function variation_price_custom_suffix( $variation_data, $product, $variation ) {
    $variation_data['price_html'] .= ' <span class="price-suffix">' . __("each", "woocommerce") . '</span>';

    return $variation_data;
}

Code goes in function.php file of your active child theme (active theme). Tested and works.

查看更多
登录 后发表回答