I am trying to find a solution to my problem. I would like to change the PayPal email based on the WooCommerce product tag. Example: for clothing, footwear and bags tags put the email emailpaypal1@domain.com ..... If the tags are snow, sun, garden, then put the email paypal2@domain.com etc ...
I found this code after several searches but i can't get it to work with tags. I tried them all but failed :(. Could anyone give me the modified code for the tags? Thank you very much !!
/**
- @snippet Switch PayPal Account @ WooCommerce Checkout
- @how-to Get CustomizeWoo.com FREE
- @author Rodolfo Melogli, BusinessBloomer.com
- @testedwith WooCommerce 4.6
- @donate $9 https://businessbloomer.com/bloomer-armada/ */
// ------------------- // 1. Switch PayPal email for Product ID
add_filter( 'woocommerce_paypal_args' , 'bbloomer_switch_paypal_email_based_product', 9999, 2 );
function bbloomer_switch_paypal_email_based_product( $paypal_args, $order ) {
foreach ( $order->get_items() as $item_id => $item ) { // ENTER PRODUCT ID HERE if ( 123456 == $item->get_product_id() ) { // ENTER OTHER PAYPAL EMAIL HERE $paypal_args['business'] = 'another-paypal@example.com'; break; } } return $paypal_args;
}
// ------------------- // 2. Avoid IPN Failure after switching PayPal email for Product ID
require_once WC()->plugin_path() . '/includes/gateways/paypal/includes/class-wc-gateway-paypal-ipn-handler.php';
class WC_Gateway_Paypal_IPN_Handler_Switch extends WC_Gateway_Paypal_IPN_Handler {
protected function validate_receiver_email( $order, $receiver_email ) { if ( strcasecmp( trim( $receiver_email ), trim( $this->receiver_email ) ) !== 0 ) { // ENTER HERE SAME PAYPAL EMAIL USED ABOVE if ( $receiver_email != 'another-paypal@example.com' ) { WC_Gateway_Paypal::log( "IPN Response is for another account: {$receiver_email}. Your email is {$this->receiver_email}" ); $order->update_status( 'on-hold', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'woocommerce' ), $receiver_email ) ); exit; } } }
}
new WC_Gateway_Paypal_IPN_Handler_Switch();
https://stackoverflow.com/questions/65756640/change-paypal-adress-based-on-tag-in-woocommerce January 17, 2021 at 10:05AM
没有评论:
发表评论