Php 在WooCommerce中显示的格式化小计中获取税务信息

Php 在WooCommerce中显示的格式化小计中获取税务信息,php,wordpress,woocommerce,cart,tax,Php,Wordpress,Woocommerce,Cart,Tax,现在我正在显示所有hte价格(如总价和运费)的税,现在我需要为小计添加相同的税值,如下图所示 我没有发现任何与此相关的内容,但cart页面需要添加新字段和其他字段,所以实际上我想将此税务信息添加到subtotal字段中。 要显示购物车小计(订单和通知),如“71540.20欧元(包括11400,00欧元增值税)”,您可以尝试使用以下内容: // Cart and checkout (for display including taxes - not compound) add_filter('

现在我正在显示所有hte价格(如总价和运费)的税,现在我需要为小计添加相同的税值,如下图所示

我没有发现任何与此相关的内容,但cart页面需要添加新字段和其他字段,所以实际上我想将此税务信息添加到subtotal字段中。

要显示购物车小计(订单和通知),如“71540.20欧元(包括11400,00欧元增值税)”,您可以尝试使用以下内容:

// Cart and checkout (for display including taxes - not compound)
add_filter('woocommerce_cart_subtotal', 'wc_cart_subtotal_incl_tax_amount_filter', 10, 3 );
function wc_cart_subtotal_incl_tax_amount_filter( $cart_subtotal, $compound, $cart ) {
    if ( wc_tax_enabled() && $cart->get_subtotal_tax() > 0 && ! $compound ) {
        $subtotal_tax   = wc_price( $cart->get_subtotal_tax() );
        $cart_subtotal  = wc_price( $cart->get_subtotal() + $cart->get_subtotal_tax() );
        $tax_label      = in_array( WC()->countries->get_base_country(), array_merge( WC()->countries->get_european_union_countries( 'eu_vat' ), array( 'NO' ) ), true ) ? __( 'VAT', 'woocommerce' ) : __( 'Tax', 'woocommerce' );
        $cart_subtotal .= sprintf( ' <small>' . esc_html__( '(includes %s %s)', 'woocommerce' ) . '</small>', $subtotal_tax, $tax_label );
    }
    return $cart_subtotal;
}

// Orders and emails (for display including taxes - not compound)
add_filter('woocommerce_order_subtotal_to_display', 'wc_order_subtotal_incl_tax_amount_filter', 10, 3 );
function wc_order_subtotal_incl_tax_amount_filter( $subtotal, $compound, $order ) {
    if ( wc_tax_enabled() && $order->get_total_tax() > 0 && ! $compound ) {
        $subtotal_tax = $subtotal = 0; // Initializing

        // Loop through order items
        foreach ( $order->get_items() as $item ) {
            $subtotal     += $item->get_subtotal() + $item->get_subtotal_tax();
            $subtotal_tax += $item->get_subtotal_tax();
        }
        $subtotal     = wc_price( $subtotal, array( 'currency' => $order->get_currency() ) );
        $subtotal_tax = wc_price( $subtotal_tax, array( 'currency' => $order->get_currency() ) );
        $tax_label    = in_array( WC()->countries->get_base_country(), array_merge( WC()->countries->get_european_union_countries( 'eu_vat' ), array( 'NO' ) ), true ) ? __( 'VAT', 'woocommerce' ) : __( 'Tax', 'woocommerce' );
        $subtotal    .= sprintf( ' <small>' . esc_html__( '(includes %s %s)', 'woocommerce' ) . '</small>', $subtotal_tax, $tax_label );
    }
    return $subtotal;
}
//购物车和结帐(用于显示,包括税费-非复合)
添加过滤器(“商业购物车小计”、“wc购物车小计”含税金额过滤器”,10,3);
函数wc\u cart\u subtotal\u incl\u tax\u amount\u filter($cart\u subtotal,$composite,$cart){
如果(wc_tax_enabled()&&$cart->get_subtotal_tax()>0&&!$component){
$subtotal_tax=wc_价格($cart->get_subtotal_tax());
$cart\u subtotal=wc\u price($cart->get\u subtotal()+$cart->get\u subtotal\u tax());
$tax_label=in_数组(WC()->countries->get_base_country(),数组_merge(WC()->countries->get_european_union_countries('eu_vat'),数组('NO')),true)?uuuu('vat woocommerce'):uu('tax','woocmerce');
$cart_subtotal.=sprintf('.esc_html_('(包括%s%s)'woocommerce'),$subtotal_tax,$tax_label);
}
返回$cart\u小计;
}
//订单和电子邮件(用于显示,包括税费-非复合)
添加过滤器(“商业、订单、小计、显示”、“wc、订单、小计、含税、金额、过滤器”,10,3);
函数wc\u order\u subtotal\u include\u tax\u amount\u filter($subtotal,$composite,$order){
如果(wc_tax_enabled()&&$order->get_total_tax()>0&&!$component){
$subtotal\u tax=$subtotal=0;//初始化
//循环浏览订单项
foreach($order->get_items()作为$item){
$subtotal+=$item->get_subtotal()+$item->get_subtotal_tax();
$subtotal_tax+=$item->get_subtotal_tax();
}
$subtotal=wc_价格($subtotal,数组('currency'=>$order->get_currency());
$subtotal\u tax=wc\u price($subtotal\u tax,数组('currency'=>$order->get\u currency());
$tax_label=in_数组(WC()->countries->get_base_country(),数组_merge(WC()->countries->get_european_union_countries('eu_vat'),数组('NO')),true)?uuuu('vat woocommerce'):uu('tax','woocmerce');
$subtotal.=sprintf(“”.esc_html_uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu;
}
返回$小计;
}

代码进入活动子主题(或活动主题)的functions.php文件。测试并正常工作。

不,我的意思是,在我的例子中,我当前显示的是包括税在内的,然后我想添加一行信息,该小计包括19%的税,正如上图中显示的其他字段,所以想知道挂钩或覆盖方法吗?