Last active
January 12, 2023 09:43
-
-
Save blivic/8f025ce0af9c80a6e22eb94765d518ec to your computer and use it in GitHub Desktop.
WooCommerce - better BACS payment instructions
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
<?php | |
/* | |
Plugin Name: MX Woo BACS | |
Plugin URI: https://media-x.hr | |
Description: Poboljšane upute za plaćanje putem direktne bankovne transakcije | |
Version: 1.0 | |
Author: Media X | |
WC requires at least: 3.0 | |
WC tested up to: 3.6.4 | |
Author URI: http://media-x.hr | |
License: GPLv3 | |
*/ | |
// Add instructions to order emails | |
add_action( 'woocommerce_email_after_order_table', 'add_bacs_order_email_instructions', 10, 2 ); // Added after the order table | |
function add_bacs_order_email_instructions( $order, $sent_to_admin ) { | |
if ( ! $sent_to_admin ) { | |
if ( 'bacs' == $order->get_payment_method() ) { | |
// change text if needed | |
echo '<h2>Podaci za plaćanje virmanom</h2>'; | |
echo '<p><strong>Primatelj:</strong> Firma d.o.o., 52100, Pula</p>'; | |
echo '<p><strong>IBAN:</strong> HR...... </p>'; | |
echo '<p><strong>Model i poziv na broj primatelja:</strong> HR00 ' . $order->get_order_number(). '</p>'; | |
echo '<p><strong>Opis plaćanja:</strong> Vaš shop narudžba ' . $order->get_order_number(). '</p>'; | |
echo '<p><strong>Iznos:</strong> ' . $order->get_total(). ' kn</p>'; | |
} | |
} | |
} | |
// Add message to thank you page if BACS | |
add_filter('woocommerce_thankyou_order_received_text', 'woo_change_order_received_text', 10, 2 ); | |
function woo_change_order_received_text( $str, $order ) { | |
if ( 'bacs' == $order->get_payment_method() ) { | |
$new_str = $str . ' Upute za plaćanje virmanom stižu u vaš inbox.'; // Additional text after default "Thank you. Your order has been received." | |
//$new_str = 'Narudžba zaprimljena. Upute za plaćanje virmanom stižu u vaš inbox.'; // Maybe you want to overwrite the text completely? Uncomment this line and comment the line above | |
return $new_str; | |
} else { | |
return $str; | |
} | |
} | |
// Remove the original bank details from email if BACS | |
add_action( 'init', 'remove_bank_details_from_email', 100 ); | |
function remove_bank_details_from_email() { | |
if ( ! class_exists( 'WC_Payment_Gateways' ) ) { | |
return; | |
} | |
$gateways = WC_Payment_Gateways::instance(); | |
$available_gateways = $gateways->get_available_payment_gateways(); | |
if ( isset( $available_gateways['bacs'] ) ) { | |
// If the gateway is available, remove the action hook | |
remove_action( 'woocommerce_email_before_order_table', array( $available_gateways['bacs'], 'email_instructions' ), 10, 3 ); | |
} | |
} | |
// Remove the original bank details from thank you page | |
add_action( 'init', 'remove_bank_details_from_thank_you_page', 100 ); | |
function remove_bank_details_from_thank_you_page() { | |
if ( ! function_exists( 'WC' ) ) { | |
return; | |
} | |
$available_gateways = WC()->payment_gateways()->get_available_payment_gateways(); | |
$gateway = isset( $available_gateways['bacs'] ) ? $available_gateways['bacs'] : false; | |
if ( false == $gateway ) { | |
return; | |
} | |
// Remove the action, which places the bank details on the thank you page | |
remove_action( 'woocommerce_thankyou_bacs', array( $gateway, 'thankyou_page' ) ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment