woocommerce - Woocommerce:以编程方式向订单添加新的增值税行
问题描述
对于特定的可变产品类别,我检查所选变体中有哪些属性。然后我必须用这 2 个不同的增值税和总额更新订单元数据。
我不需要显示默认的 woocommerce 增值税详细信息行,而是需要显示这 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
}
但我不知道这是否是好方法。
解决方案
推荐阅读
- linux - BASH,if 语句未按预期运行
- spring - Spring data rest - 复合主键的发布请求
- vim - vimrc:仅对某些文件类型执行多行
- java - 带有类对象的 Java 集合不起作用
- php - 无法创建新信号量,因为“设备上没有剩余空间” - 我似乎超出了信号量数组数量的限制
- python - 非结构化数据,NLP Lemmatize 书评
- java - Maven 生成没有资源的 Spring 和 Thymeleaf 应用程序
- python - Pandas 在数据框获取 df.style 后创建一个新列
- html - Safari 中的插入符号问题与 contenteditable SVG
- python - Python plotly express 带有累积总和的折线图