Last active
November 10, 2024 08:56
-
-
Save david-strejc/2b31accfdd1615bf1527c1cd8afd8eba to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action('woocommerce_thankyou_bacs', 'wpd_qr_code', 10, 1 ); | |
function wpd_qr_code( $order_id ) { | |
$order = wc_get_order( $order_id ); | |
$bacs_info = get_option( 'woocommerce_bacs_accounts'); | |
echo "<div style='display: grid; grid-template-columns: auto auto auto;'>"; | |
foreach ($bacs_info as $info ) { | |
$account = explode( "/", $info['account_number']) ? explode( "/", $bacs_info[0]['account_number']) : null ; | |
if (! $account) { | |
return; | |
} | |
$currency = $info['account_name']; | |
$bank_name = $info['bank_name']; | |
$account_number = $account[0] ; | |
$bank_code = $account[1]; | |
$amount = $order->get_total(); | |
$variable_symbol = $order->get_id(); | |
$message = get_bloginfo('name'); | |
echo '<div style="margin-bottom: 30px;">'; | |
echo '<h3>'; | |
echo $currency; | |
echo '</h3>'; | |
echo '<h4>'; | |
echo $account_number; | |
echo '</h4>'; | |
echo '<h5>'; | |
echo $bank_name; | |
echo '</h5>'; | |
echo '<img src="//api.paylibo.com/paylibo/generator/czech/image?accountNumber=' . $account_number | |
. '&bankCode=' . $bank_code | |
. '&amount=' . $amount | |
. '¤cy=' . $currency | |
. '&vs=' . $variable_symbol | |
. '&message=' . $message . '" />'; | |
echo '</div>'; | |
} | |
echo '</div>'; | |
} | |
add_action( 'woocommerce_email_after_order_table', 'wpd_qr_email', 15 ); | |
function wpd_qr_email( $order ) { | |
if ($order->get_payment_method() != 'bacs') { | |
return; | |
} | |
$bacs_info = get_option( 'woocommerce_bacs_accounts'); | |
$account = explode( "/", $bacs_info[0]['account_number']) ? explode( "/", $bacs_info[0]['account_number']) : null ; | |
if (! $account) { | |
return; | |
} | |
echo "<div style='display: grid; grid-template-columns: auto auto auto;'>"; | |
foreach ($bacs_info as $info ) { | |
$account = explode( "/", $info['account_number']) ? explode( "/", $bacs_info[0]['account_number']) : null ; | |
if (! $account) { | |
return; | |
} | |
$currency = $info['account_name']; | |
$bank_name = $info['bank_name']; | |
$account_number = $account[0] ; | |
$bank_code = $account[1]; | |
$amount = $order->get_total(); | |
$variable_symbol = $order->get_id(); | |
$message = get_bloginfo('name'); | |
echo '<div style="margin-bottom: 30px;">'; | |
echo '<h3>'; | |
echo $currency; | |
echo '</h3>'; | |
echo '<h4>'; | |
echo $account_number; | |
echo '</h4>'; | |
echo '<h5>'; | |
echo $bank_name; | |
echo '</h5>'; | |
echo '<img src="//api.paylibo.com/paylibo/generator/czech/image?accountNumber=' . $account_number | |
. '&bankCode=' . $bank_code | |
. '&amount=' . $amount | |
. '¤cy=' . $currency | |
. '&vs=' . $variable_symbol | |
. '&message=' . $message . '" />'; | |
echo '</div>'; | |
} | |
echo '</div>'; | |
} |
$amount = $order->get_total();
Já vím,že to je hook, takže by jste měl dostávat relevantní data do toho filtru ale stejně bych dal nějakou kontrolu nebo alespoň try and catch toho,že order je objekt a že explody fungují jak mají. Vy tam ani nekontrolujete jestli array key existuje a mohlo by to házet undefined offset.Jinak ale pěkná práce
Jinak tam toho samozrejme chybi mnohem vic - kontrola, ze je to pro BACS only a tak dale.
Komerční banky vyžaduje předčíslí (příklad. 107-9055200297/0100) tz. s timto hookem nefunguje :( škoda.
Je to stale funkcni?
Zatim vyzera ze ano, jedinej problem je ze na emailovy sablon tam se nedokaze ten QR pro platbu
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ja jsem psal, ze je to "quick and dirty" - ve woo neni potreba psat ucet ve formatu "ucet"/"kod" - melo by to mit vlastni config popripade je treba obohacovat WooCommerce Bank Accounty o bank account info a tak dale - neni tam foreach pro vic bank accountu, nejsou tam meny. Je to PoC.