将 PayPal 和 BACS 添加到 Klarna Checkout
Add PayPal and BACS to Klarna Checkout
我正在尝试将 PayPal 和 BACS(银行转账)添加到我的 WooCommerce Klarna Checkout。
找到了示例插件
这非常有效,但是当我尝试更改代码以显示和使用 BACS 付款时,我只显示了 BACS 选项,而没有显示 PayPal 和 BACS。
这是krokedil提供的PayPal示例代码(后台插件设置的代码我已经删掉了):
add_filter( 'kco_wc_api_request_args', 'kcoepm_create_order_paypal' );
function kcoepm_create_order_paypal( $request_args ) {
$kco_settings = get_option( 'woocommerce_kco_settings' );
$name = isset( $kco_settings['epm_paypal_name'] ) ? $kco_settings['epm_paypal_name'] : '';
$image_url = isset( $kco_settings['epm_paypal_img_url'] ) ? $kco_settings['epm_paypal_img_url'] : '';
$description = isset( $kco_settings['epm_paypal_description'] ) ? $kco_settings['epm_paypal_description'] : '';
$klarna_external_payment = array(
'name' => $name,
'image_url' => $image_url,
'description' => $description,
'redirect_url' => add_query_arg(
array(
'kco-external-payment' => 'paypal', // Set this to the ID of the relevant payment method in WooCommerce.
'order_id' => isset( $request_args['merchant_reference2'] ) ? $request_args['merchant_reference2'] : '{checkout.order.id}',
),
wc_get_checkout_url()
),
);
$klarna_external_payment = array( $klarna_external_payment );
$request_args['external_payment_methods'] = $klarna_external_payment;
return $request_args;
}
我想出了以下代码,它确实会显示 BACS 付款方式并允许付款。然而,当我启用我的代码时,PayPal 支付选项很快就会消失。
add_filter( 'kco_wc_api_request_args', 'kcoepm_create_order_bacs' );
function kcoepm_create_order_bacs( $request_args ) {
$klarna_external_payment = array(
'name' => 'BACS',
'image_url' => 'https://via.placeholder.com/350x150',
'description' => 'Pay via Banktransfer',
'redirect_url' => add_query_arg(
array(
'kco-external-payment' => 'bacs', // Set this to the ID of the relevant payment method in WooCommerce.
'order_id' => isset( $request_args['merchant_reference2'] ) ? $request_args['merchant_reference2'] : '{checkout.order.id}',
),
wc_get_checkout_url()
),
);
$klarna_external_payment = array( $klarna_external_payment );
$request_args['external_payment_methods'] = $klarna_external_payment;
return $request_args;
}
我不知道如何同时注册两种支付方式。我觉得跟数组没有注册有关系
我在 krokedik 文档中找到了这个通知,但不知道如何实现它:
“发送给 Klarna 的请求中的每个定义的外部支付方式都应添加为数组,如此处文档中所述:https://developers.klarna.com/api/#checkout-api__create-a-new-order__external_payment_methods."
如有任何帮助,我们将不胜感激!
此代码将两种付款方式添加到结帐中:
https://gist.github.com/flymke/c5f49b52c8ecf5069c68b6d9a4e84c76
您需要将两个 $klarna_external_payments
数组添加到 $request_args['external_payment_methods']
。
确保您已将付款方式更改为正确的 ID,在我的示例中,PayPal 称为“ppec_paypal”,因为我们使用的是 PayPal 快速结账而不是常规 PayPal:'kco-external-payment'
= > 'ppec_paypal'
。
您可以在代码中找到它:
// Set this to the ID of the relevant payment method in WooCommerce.
我正在尝试将 PayPal 和 BACS(银行转账)添加到我的 WooCommerce Klarna Checkout。
找到了示例插件这非常有效,但是当我尝试更改代码以显示和使用 BACS 付款时,我只显示了 BACS 选项,而没有显示 PayPal 和 BACS。
这是krokedil提供的PayPal示例代码(后台插件设置的代码我已经删掉了):
add_filter( 'kco_wc_api_request_args', 'kcoepm_create_order_paypal' );
function kcoepm_create_order_paypal( $request_args ) {
$kco_settings = get_option( 'woocommerce_kco_settings' );
$name = isset( $kco_settings['epm_paypal_name'] ) ? $kco_settings['epm_paypal_name'] : '';
$image_url = isset( $kco_settings['epm_paypal_img_url'] ) ? $kco_settings['epm_paypal_img_url'] : '';
$description = isset( $kco_settings['epm_paypal_description'] ) ? $kco_settings['epm_paypal_description'] : '';
$klarna_external_payment = array(
'name' => $name,
'image_url' => $image_url,
'description' => $description,
'redirect_url' => add_query_arg(
array(
'kco-external-payment' => 'paypal', // Set this to the ID of the relevant payment method in WooCommerce.
'order_id' => isset( $request_args['merchant_reference2'] ) ? $request_args['merchant_reference2'] : '{checkout.order.id}',
),
wc_get_checkout_url()
),
);
$klarna_external_payment = array( $klarna_external_payment );
$request_args['external_payment_methods'] = $klarna_external_payment;
return $request_args;
}
我想出了以下代码,它确实会显示 BACS 付款方式并允许付款。然而,当我启用我的代码时,PayPal 支付选项很快就会消失。
add_filter( 'kco_wc_api_request_args', 'kcoepm_create_order_bacs' );
function kcoepm_create_order_bacs( $request_args ) {
$klarna_external_payment = array(
'name' => 'BACS',
'image_url' => 'https://via.placeholder.com/350x150',
'description' => 'Pay via Banktransfer',
'redirect_url' => add_query_arg(
array(
'kco-external-payment' => 'bacs', // Set this to the ID of the relevant payment method in WooCommerce.
'order_id' => isset( $request_args['merchant_reference2'] ) ? $request_args['merchant_reference2'] : '{checkout.order.id}',
),
wc_get_checkout_url()
),
);
$klarna_external_payment = array( $klarna_external_payment );
$request_args['external_payment_methods'] = $klarna_external_payment;
return $request_args;
}
我不知道如何同时注册两种支付方式。我觉得跟数组没有注册有关系
我在 krokedik 文档中找到了这个通知,但不知道如何实现它:
“发送给 Klarna 的请求中的每个定义的外部支付方式都应添加为数组,如此处文档中所述:https://developers.klarna.com/api/#checkout-api__create-a-new-order__external_payment_methods."
如有任何帮助,我们将不胜感激!
此代码将两种付款方式添加到结帐中: https://gist.github.com/flymke/c5f49b52c8ecf5069c68b6d9a4e84c76
您需要将两个 $klarna_external_payments
数组添加到 $request_args['external_payment_methods']
。
确保您已将付款方式更改为正确的 ID,在我的示例中,PayPal 称为“ppec_paypal”,因为我们使用的是 PayPal 快速结账而不是常规 PayPal:'kco-external-payment'
= > 'ppec_paypal'
。
您可以在代码中找到它:
// Set this to the ID of the relevant payment method in WooCommerce.