がある:「https://www.floorcare-supplies.co.uk/product-category/machines/」表示価格
私はせずに、特にこのカテゴリーの製品を表示することができるように探しています店頭の税金。
私は例えば製品にするときにそれを行うことができた:
£1342
は£1123例バット
しかし、店の店舗に、私は表示するために、メインの価格を必要としますその特定のカテゴリのための税なし合計。
がある:「https://www.floorcare-supplies.co.uk/product-category/machines/」表示価格
私はせずに、特にこのカテゴリーの製品を表示することができるように探しています店頭の税金。
私は例えば製品にするときにそれを行うことができた:
£1342
は£1123例バット
しかし、店の店舗に、私は表示するために、メインの価格を必要としますその特定のカテゴリのための税なし合計。
使用このコード:
/**
* Function that will check for category id and turn off VAT/tax
*/
function wc_diff_rate_for_cat() {
if (is_product_category ('machines')) {
// set the machines category to have no VAT
WC()->customer->is_vat_exempt = true;
}
}
add_action('template_redirect', 'wc_diff_rate_for_cat', 1);
/**
* Function that filters the variable product hash based on category
*/
function wc_get_variation_prices_hash_filter($hash, $item, $display) {
// check for the "machines" category
if (is_product_category ('machines')) {
// clear key 2, which is where taxes are
$hash['2'] = array();
}
// return the hash
return $hash;
}
add_filter('woocommerce_get_variation_prices_hash', 'wc_get_variation_prices_hash_filter', 1, 3);
/**
* Function that removes the price suffix (inc. Tax) from variable products based on category
*/
function wc_get_price_suffix_filter($price_display_suffix, $item) {
if (is_product_category ('machines')) {
// return blank if it matches
return '';
}
// return if unmatched
return $price_display_suffix;
}
add_filter('woocommerce_get_price_suffix', 'wc_get_price_suffix_filter', 10, 2);
が解決
ソリューション
修正子テーマ
Woocommerce \を含めることは\ WC-テンプレートのfunctions.phpを含み
&
woocommerceの\ループの\ price.php
コードWoocommerce \表示するpricemod.php
global $product;
$vat = "Ex vat ";
?>
<p class="price"><?php echo $product->get_price_html(); ?></p>
<p class="priceex"><?php echo woocommerce_price($product->get_price_excluding_tax()). ' ' . $vat; ?></p>
親切に、しかし**これは良い解決策ではありません* *あなたがコアファイルを上書きする**:Woocommerce \ includes \ wc-template-functions。php ...正しい方法はフック 'wc_price'を使うことです。ソリューションのAlsloでは、「機械」製品カテゴリーをターゲットにしていません。 – LoicTheAztec
変性そしてWC-テンプレートのfunctions.php \
/**
* Get the product price for the loop.
*
* @subpackage Loop
*/
function woocommerce_template_loop_price() {
wc_get_template('loop/pricemod.php');
}
を含む に添加「機械」製品カテゴリの税金を除いた価格では、カスタム機能を使用する必要がありますwc_price
フィルターフック、この方法:
add_filter('wc_price', 'product_category_price_excl_tax', 10, 3);
function product_category_price_excl_tax( $price_html, $price, $args){
global $post;
// Price excluding taxes for "Machines" product category with corresponding label
if(has_term('Machines', 'product_cat', $post->ID)){
$decimal_separator = wc_get_price_decimal_separator();
$thousand_separator = wc_get_price_thousand_separator();
$decimals = wc_get_price_decimals();
$price_format = get_woocommerce_price_format();
$number_format = number_format($price, $decimals, $decimal_separator, $thousand_separator);
$negative = $price < 0;
$currency = get_woocommerce_currency();
// Get an instance of the WC_Product object
$product = wc_get_product($post->ID);
// Get the product price excluding taxes
$price = wc_get_price_excluding_tax($product, $price);
$price = apply_filters('raw_woocommerce_price', floatval($negative ? $price * -1 : $price));
$price = apply_filters('formatted_woocommerce_price', $number_format, $price, $decimals, $decimal_separator, $thousand_separator);
if (apply_filters('woocommerce_price_trim_zeros', false) && $decimals > 0)
$price = wc_trim_zeros($price);
$formatted_price = ($negative ? '-' : '') . sprintf($price_format, '<span class="woocommerce-Price-currencySymbol">' . get_woocommerce_currency_symbol($currency) . '</span>', $price);
$price_html = '<span class="woocommerce-Price-amount amount">' . $formatted_price . '</span>';
if (wc_tax_enabled())
$price_html .= ' <small class="woocommerce-Price-taxLabel tax_label">' . WC()->countries->ex_tax_or_vat() . '</small>';
}
return $price_html;
}
コードは、あなたのアクティブな子テーマ(またはテーマ)のfunction.phpファイルやも任意のプラグインファイルになります。
このコードは、テストされ、価格はのみ「マシン」ショップカテゴリアーカイブのページで、あなたが交換する必要があることを表示するために、WooCommerce版今3+
のために動作します:
if(has_term('Machines', 'product_cat', $post->ID)){
:
if(has_term('Machines', 'product_cat', $post->ID) && is_product_category ('machines')){
ありがとうございましたあなたの答えは、これは動作しませんまた、私はカテゴリーの免税を免除する必要はありません、私はちょうど店ではなく税金のない価格を表示したい –