Adding custom text to the variation price in Woocommerce

二次信任 提交于 2020-03-23 10:58:07

问题


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' );

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:


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.



来源:https://stackoverflow.com/questions/52599426/adding-custom-text-to-the-variation-price-in-woocommerce

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!