フィルタwoocommerce_get_price_including_tax
を単一の製品ページで使用してください。関数get_price_including_tax
からコードをコピーしました。私はこのコードをテストしていませんが、これはあなたがしなければならないことの基本的な考え方です。
function modify_woocommerce_get_price_including_tax($price, $qty, $product) {
if(! is_checkout()) {
$tax_rates = WC_Tax::get_rates($product->get_tax_class());
$base_tax_rates = WC_Tax::get_base_tax_rates($product->tax_class);
if (! empty(WC()->customer) && WC()->customer->is_vat_exempt()) {
$base_taxes = WC_Tax::calc_tax($price * $qty, $base_tax_rates, true);
$base_tax_amount = array_sum($base_taxes);
$price = round($price * $qty - $base_tax_amount, wc_get_price_decimals());
/**
* The woocommerce_adjust_non_base_location_prices filter can stop base taxes being taken off when dealing with out of base locations.
* e.g. If a product costs 10 including tax, all users will pay 10 regardless of location and taxes.
* product feature is experimental @since 2.4.7 and may change in the future. Use at your risk.
*/
} elseif ($tax_rates !== $base_tax_rates && apply_filters('woocommerce_adjust_non_base_location_prices', true)) {
$base_taxes = WC_Tax::calc_tax($price * $qty, $base_tax_rates, true);
$modded_taxes = WC_Tax::calc_tax(($price * $qty) - array_sum($base_taxes), $tax_rates, false);
$price = round(($price * $qty) - array_sum($base_taxes) + array_sum($modded_taxes), wc_get_price_decimals());
} else {
$price = $price * $qty;
}
}
return $price;
}
add_filter('woocommerce_get_price_including_tax', 'modify_woocommerce_get_price_including_tax', 10, 3);
あなたは、カートページで価格を変更したい場合、あなたはあなたの子供をテーマにテンプレートcart-totals.php
をオーバーライドする必要があります。
Hey Andrewご回答いただきありがとうございます。 1つの商品ページに税込み価格または税抜き価格を表示することができます。 私に問題を起こしているカートのページです。 – user3596056
あなたはあなたの質問にそれを指定していません。私は指示で私の答えを更新しました。基本的にcart-totals.phpというテンプレートはフィルターがないので修正する必要があります。 –