php - Multiple PayPal accounts linked to ONE installation of Woocommerce -


my issue: client has 12 locations, each location different corporation hence different paypal account per business. default woocommerce supports 1 email entered process payment. goal use 1 installation of wordpress / woocommerce direct user paypal account associated location have selected upon checkout.

my theory / attempt: thought of implementing feature setting variation user can select location pass parameter url. parameter later used within php overwrite default email.

my problem: having trouble overwriting default email entered within admin settings, cant seem locate email in database. assuming file pertaining modification located at: wp-content/plugins/woocommerce/includes/gateways/paypal prefer doing wordpress way vs editing core files, obvious reasons. after doing research have found following action shown below, proceed checkout button, looking interact proceed paypal button. fluent in php not best wordpress development. think popular issue since majority of franchises deal such scenario, unpleasantly surprised on amount of information regarding topic. if point me in right direction of conquering task appreciated!

remove_action('woocommerce_proceed_to_checkout','woocommerce_button_proceed_to_checkout', 20);  add_action('woocommerce_proceed_to_checkout', 'change_url_to_checkout', 20);  function change_url_to_checkout(){         $extra_url = 'put_your_extra_page_url_here';         ?>         <a href="<?php echo $extra_url; ?>" class="checkout-button button alt wc-forward"><?php _e( 'proceed checkout', 'woocommerce' ); ?></a>         <?php    }    

i can see 2 functions written here.

 1. alter order data when order created. save email needed.

add_action( 'woocommerce_checkout_update_order_meta', 'woocommerce_checkout_update_order_meta' ); function woocommerce_checkout_update_order_meta( $order_id ) {     $email = 'paypal@location1.com';     // here use right email.     // have $order_id.     // can used as:     // $order = wc_get_order( $order_id );     // $order->get_billing_address_1() address check order address.     // or use $_post['location'] if ever posted data.     update_post_meta( $order_id, '_alternative_paypal_email', $email ); } 

 2. use woocommerce_paypal_args alter args being passed paypal.

add_filter( 'woocommerce_paypal_args', 'woocommerce_paypal_args', 10, 2 ); function woocommerce_paypal_args( $paypal_args, $order ) {     $email = get_post_meta( $order->get_id(), '_alternative_paypal_email', true );     if ( !empty( $email ) ) {         $paypal_args['business'] = $email;     }     return $paypal_args; } 

to summarize, example. these 2 hooks enough need.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -