对于特定的可变产品类别,我会检查所选变体中的哪些属性。然后我必须用这 2 个不同的增值税和总额更新订单元数据。
不是显示默认的 woocommerce VAT 详细信息行,我需要显示这 2 行和总数。
我在 woocommerce 中不显示增值税,所以也许它可以显示为费用行,重要的是它显示在发票上。
我从以下代码开始:
add_action('woocommerce_checkout_before_order_review', 'get_cart_info_woo');
function get_cart_info_woo() {
global $woocommerce;
foreach ( $woocommerce->cart->cart_contents as $product ) {
$terms = get_the_terms( $product['product_id'], 'product_cat' );
$inscription = $terms[0]->term_id;
if ( $inscription == 19 )
{ /// if registering product
$accomodation = $product['variation']['attribute_pa_hebergement'];
$price = $product['variation']['attribute_pa_tarif'];
}
}
// get the integers in the strings
$accomodation_price = (int) filter_var($accomodation, FILTER_SANITIZE_NUMBER_INT);
$price = (int) filter_var($price, FILTER_SANITIZE_NUMBER_INT);
// vat calculations
$accomodation_vat = $accomodation_price / 1.055 ;// VAT (5.5%)
$price_vat = $_price / 1.2 ;// VAT (20%)
//here update order VAT meta with $accomodation_vat and $price_vat as 2 different vat lines
}
但我不知道这是不是好方法。