I have a WooCommerce store in which one product can be personalized by more than one artist. Every artist have their own bank account to receive their payment; so I need the bank account that appears in the thankyou page, and in the corresponding email, be the one belonging to the chosen artist. To identify each bank account and artist, I did the next:
- I assigned a 3 character identifier using the slug for every product variation (artist).
- I also assigned the same 3 character identifier using the sort code field for every bank account in the payment gateway.
Now, I need to find which bank account have a sort code equal to the selected variation slug account_details[x]['sort_code'] = (the variation slug)
Can someone point me in the right direction? I need a loop that disables all the rows in account_details
except for the one that matches the variation slug.
I found the way to select the bank account by comparing it to a a string. To do so, I added the condition if ( $bacs_account->sort_code != 'ztc' ) { continue; }
in line 255 of the file class-wc-gateway-bacs.php
foreach ( $bacs_accounts as $bacs_account ) {
$bacs_account = (object) $bacs_account; if ( $bacs_account->sort_code != 'ztc' ) { continue; }
if ( $bacs_account->account_name ) {
$account_html .= '<h3 class="wc-bacs-bank-details-account-name">' . wp_kses_post( wp_unslash( $bacs_account->account_name ) ) . ':</h3>' . PHP_EOL;
However, I cant find the way to get the variation slug to compare it to $bacs_account->sort_code
(instead of the string). Also, I think it would be better this to be modified by the functions.php file instead of messing with the class-wc-gateway-bacs.php file.
Can someone can help me in order to do any of this?
Done!
Found the way to get the variation slug from
https://stackoverflow.com/questions/53009224/get-order-item-meta-data-in-an-unprotected-array-in-woocommerce-3
. So I just added:foreach ( $order->get_items() as $item ) {$sede = $item->get_meta("pa_sede");}; if ( $bacs_account->sort_code != $sede ) { continue; };
after line 255 in the file "class-wc-gateway-bacs.php". I also commented lines 272-275 to hide the sort code field as it is usefull to select the account, but has no use for the user.
Everything is working just as expected.
I worked on a similar situation, but I enabled gateways on the checkout page. Gateways changes after every order in a cyclic fashion. Suppose first order used gateway 1, second uses gateway 2, third gateway 3 again 4 uses gateway 1. I have used CSS to hide / display only one gateway at a time based on gateway used for previous order.
So in your case, get the slug url and based on that there should be some styling convention followed in BACS displayed from using which you can disable other gateways.
To get slug in case you have not: 1.First get the product id from order id. 2. Then you can get the slug using product id (Woocommerce: How do I get the product slug from the id? )
Hope that helps.