显示Woocommerce选择的含税和不含税的产品变动价格

问题描述 投票:1回答:1

我想显示Woocommerce选择的含税和不含税的产品变化价格。 &价格应根据产品变化自动更改。

OR

如何获得选定的变化价格?这也将有助于自定义功能。

php wordpress woocommerce product price
1个回答
0
投票

以下将显示选定的不带税和不带税的变动价格:

add_filter( 'woocommerce_available_variation', 'custom_variation_price_display', 10, 3 );
function custom_variation_price_display( $data, $product, $variation ) {
    $price_excl_tax = (float) wc_get_price_excluding_tax( $variation ); // price without Tax
    $price_incl_tax = (float) wc_get_price_including_tax( $variation );  // price with Tax

    $data['price_html'] = '<span class="ex-vat-price">' . wc_price($price_excl_tax) . ' <em>' . __("(Excl. tax)", "woocommerce") . '</em></span><br>
    <span class="inc-vat-price">' . wc_price($price_incl_tax) . ' <em>' . __("(Incl. tax)", "woocommerce") . '</em></span>';

    return $data;
}

代码进入您的活动子主题(或活动主题)的functions.php文件中。经过测试和工作。

相关:Display tax amount based on specific tax class in WooCommerce variations

© www.soinside.com 2019 - 2024. All rights reserved.