我尝试根据我在 Woocommerce 购物车上所做的一些计算来增加费用,但我想将其从增值税中排除。这是我的代码:
function woo_add_cart_fee( $cart ) {
global $woocommerce; $bookable_total = 0;
foreach(WC()->cart->get_cart() as $cart_item_key => $values) {
$_product = $values['data'];
//doing my stuff to calculate $fee variable
WC()->cart->add_fee( 'Fees: ', $fee, false, '' );
//WC()->cart->add_fee( 'Fees: ', $fee, true, '' );
//WC()->cart->add_fee( 'Fees: ', $fee, false, 'zero rate' );
//WC()->cart->add_fee( 'Fees: ', $fee, true, 'zero rate' );
}
add_action( 'woocommerce_cart_calculate_fees', 'woo_add_cart_fee' );
Run Code Online (Sandbox Code Playgroud)
我已经尝试了所有评论版本,每个版本也都包含增值税。
知道我如何实现它吗?
我正在“即时”创建 Woocommerce 总计,因为我的购物车项目是从另一个 CMS 导入的。
目前,我无法为每个订单设置自定义“费用”,然后将订单标记为“暂停”:
$order->set_date_created($creation_tsz);
$order->set_address( $address, 'billing' );
$order->set_address( $address, 'shipping' );
$order->set_currency('GBP');
$order->add_fee('Imported Total', $imported_total_here);
$order->set_fee();
$order->calculate_totals();
$order->update_status('on-hold');
Run Code Online (Sandbox Code Playgroud)
任何关于此的曲目将不胜感激。
选择付款方式(信用卡)时如何添加总金额的百分比?
\n\n例如:如果客户支付的是货到付款,那么是底价,如果我选择网上支付,那么我收取的百分比是加到总金额中的吗?
\n\n货到付款网关ID设置:cod\n网上支付网关ID设置:tinkoff
\n\nadd_action( \'woocommerce_after_calculate_totals\', \'custom_fee_for_tinkoff\' );\n\nfunction custom_fee_for_tinkoff( $cart ) {\n\n if ( is_checkout() || defined(\'WOOCOMMERCE_CHECKOUT\') ) {\n\n $payment_method = WC()->session->get( \'chosen_payment_method\' );\n\n if ($payment_method == \'tinkoff\') {\n $percentage = 0.025;\n $surcharge = ( $cart->cart_contents_total + $cart->tax_total ) * $percentage;\n\n $cart->add_fee( \'\xd0\x9a\xd0\xbe\xd0\xbc\xd0\xb8\xd1\x81\xd1\x81\xd0\xb8\xd1\x8f \xd0\xb1\xd0\xb0\xd0\xbd\xd0\xba\xd0\xb0\', $surcharge, true, \'\' );\n }\n else { return; }\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n\n\n 在 woocommerce 的结帐中添加多项费用时,是否可以优先考虑它们的顺序?目前看来 woocommerce 按费用值对它们进行排序,因此例如:费用 1 = \xc2\xa310.00,费用 2 = \xc2\xa320.00,它们将按如下方式排序:
\n\n是否可以定制订单?也许可以为附加费用的操作添加优先级?我希望Fee 2永远是最后一个收费项目。
这是可以实现的吗?
\n我试着在Woocommerce中获得订单附加费用的名称,我得到一个阵列,但我不知道如何得到这个名字.
我试过功能,get_name ()但它不起作用.
$the_order->get_items( array( 'line_item', 'fee', 'shipping' ) );
Run Code Online (Sandbox Code Playgroud)
原始数据输出:
[137] => WC_Order_Item_Fee Object
(
[extra_data:protected] => Array
(
[tax_class] =>
[tax_status] => taxable
[amount] =>
[total] =>
[total_tax] =>
[taxes] => Array
(
[total] => Array
(
)
)
)
[data:protected] => Array
(
[order_id] => 7795
[name] => Frais de réservation
[tax_class] => 0
[tax_status] => taxable
[amount] =>
[total] => 35
[total_tax] => 0
[taxes] => Array
(
[total] => Array
(
)
) …Run Code Online (Sandbox Code Playgroud) 我想在 woocommerce 结帐页面上添加自定义 % 值,但我只想对瑞士国家/地区显示它,而对其他国家/地区隐藏它。现在我有了正确的代码,但问题是当用户选择瑞士时我无法显示它。这是一个代码,所以请帮我看看我在这里做错了什么
//Add tax for CH country
add_action( 'woocommerce_cart_calculate_fees','woocommerce_custom_surcharge' );
function woocommerce_custom_surcharge() {
global $woocommerce;
if ( WC()->customer->get_shipping_country('CH') )
return;
$percentage = 0.08;
$taxes = array_sum($woocommerce->cart->taxes);
$surcharge = ( $woocommerce->cart->cart_contents_total + $woocommerce->cart->shipping_total ) * $percentage;
// Make sure that you return false here. We can't double tax people!
$woocommerce->cart->add_fee( 'TAX', $surcharge, false, '' );
}
Run Code Online (Sandbox Code Playgroud)
我确定我在这里做错了:
if ( WC()->customer->get_shipping_country('CH') )
Run Code Online (Sandbox Code Playgroud)
感谢帮助