相关疑难解决方法(0)

为 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
查看次数

基于 Woocommerce 中的用户角色和付款方式的百分比折扣

我试图为functions.php 编写一个代码片段,当同时选择角色“订阅者”和付款方式“信用卡”时,该代码片段会对购物车总额应用2% 的折扣。到目前为止我的进展

function discount_when_role_and_payment(/* magic */) {
global $woocommerce;
if ( /* credit-card selected */ && current_user_can('subscriber') ) {
    /* get woocommerce cart totals, apply 2% discount and return*/
} 
return /*cart totals after discount*/;
}

add_filter( '/* magic */', 'discount_when_role_and_payment' );
Run Code Online (Sandbox Code Playgroud)

有人可以帮忙完成这个吗?或者至少指向正确的方向?

php wordpress checkout woocommerce hook-woocommerce

2
推荐指数
1
解决办法
1670
查看次数

在 Woocommerce 中根据运输方式和付款方式添加费用

当客户可以下订单免运费,但想选择 COD 付款时,我需要申请额外费用。所以,免费送货 + COD 付款 => 费用。

我尝试了以下代码未成功。我哪里错了?

add_action( 'woocommerce_cart_calculate_fees','cod_fee' );
function cod_fee() {
    global $woocommerce;

    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
        return;

        $chosen_gateway = WC()->session->chosen_payment_method;
        $chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
        $chosen_shipping = $chosen_methods[0]; 
        $fee = 19;
        if ( $chosen_shipping == 'free_shipping' && $chosen_gateway == 'cod' ) { 
        WC()->cart->add_fee( 'Spese per pagamento alla consegna', $fee, false, '' );
    }
}
Run Code Online (Sandbox Code Playgroud)

php wordpress jquery checkout woocommerce

2
推荐指数
1
解决办法
2138
查看次数

标签 统计

php ×3

woocommerce ×3

wordpress ×3

checkout ×2

jquery ×2

fee ×1

hook-woocommerce ×1