小编Вик*_*нко的帖子

为 Woocommerce 中的特定支付网关添加自定义费用

选择付款方式(信用卡)时如何添加总金额的百分比?

\n\n

例如:如果客户支付的是货到付款,那么是底价,如果我选择网上支付,那么我收取的百分比是加到总金额中的吗?

\n\n

货到付款网关ID设置:cod\n网上支付网关ID设置:tinkoff

\n\n
add_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}\n
Run Code Online (Sandbox Code Playgroud)\n\n

有问题的图像

\n

php wordpress jquery woocommerce fee

4
推荐指数
1
解决办法
2054
查看次数

标签 统计

fee ×1

jquery ×1

php ×1

woocommerce ×1

wordpress ×1