AI要約
WPFormsとPayPal Commerceを使用していて、PayPalボタンのみで支払いを受け付けたい非営利団体ですか?デフォルトでは、PayPal CommerceはApple Pay、Google Pay、Venmo、Pay Later、およびiDEALやBancontactなどの地域の方法といった、いくつかの代替の支払い方法を有効にします。PayPalの割引料金の対象となる非営利団体アカウントは、その料金を維持するために、チェックアウトをPayPalボタンに制限する必要があることがよくあります。
このチュートリアルでは、カスタムコードスニペットを使用してPayPal Commerceのすべての代替支払い方法を無効にし、PayPalボタンのみをアクティブにする方法を説明します。
スニペットの追加
必須プラグインを設定したか、WPCodeをインストールしたら、次のスニペットをサイトに追加してください。
<?php
/**
* Restrict WPForms PayPal Commerce to the PayPal button only.
*
* @link https://wpforms.com/developers/
*/
// Prevent Apple Pay and Google Pay from registering their SDK components.
add_filter( 'wpforms_integrations_paypal_commerce_payment_methods_apple_pay_allow_load', '__return_false' );
add_filter( 'wpforms_integrations_paypal_commerce_payment_methods_google_pay_allow_load', '__return_false' );
// Disable the remaining alternative funding sources.
add_filter(
'wpforms_integrations_paypal_commerce_frontend_get_disabled_funding_sources',
function ( $disabled, $is_single ) {
return array_unique(
array_merge(
$disabled,
[
'card',
'credit',
'paylater',
'venmo',
'bancontact',
'blik',
'eps',
'giropay',
'ideal',
'mybank',
'p24',
'sepa',
'sofort',
'trustly',
'wechatpay',
'mercadopago',
]
)
);
},
10,
2
);
// Clear any explicitly enabled funding sources (such as Venmo).
add_filter( 'wpforms_integrations_paypal_commerce_frontend_get_enabled_funding_sources', '__return_empty_array', 10, 2 );
このスニペットは3つの部分で機能し、それぞれPayPal Commerceの読み込みプロセスの異なるステージにフックします。最初の2つのフィルターは、Apple PayとGoogle PayがSDKコンポーネントを完全に登録するのを防ぎます。このステップは、これらの支払い方法を無効にするだけで読み込みを防がないと、PayPal.jsスクリプトが失敗する可能性があるため重要です。
次のフィルター、 wpforms_integrations_paypal_commerce_frontend_get_disabled_funding_sourcesは、残りの代替支払い方法をPayPalの無効リストに追加します。これには、クレジットカードとデビットカード、Pay Later、Venmo、およびiDEAL、Bancontact、SEPAなどのさまざまな地域の方法が含まれます。
最後のフィルターは、明示的に有効化された支払い方法をすべてクリアし、何も漏れないようにします。
これらのフィルターを組み合わせることで、PayPalボタンがフォームで利用可能な唯一の支払い方法となります。支払いは通常どおり処理され、非営利団体アカウントは割引料金を維持できます。
これで完了です!PayPal CommerceをPayPalボタンのみに正常に制限しました。WPFormsでの支払い受け付けについて、さらに詳しく知りたいですか?WPFormsでのPayPal Commerceの設定に関する完全ガイドをご覧ください こちら。