Changing BACS workflow & mailings
-
Hello,
I’m currently trying to modify the processing flow for BACS. I’ve gotten it to work, but it feels like “A very dirty hack”(TM), so I’d like to know if there’s a better way to do it.
What I want to do:
* Customer puts order in
* Order gets moved immediately to processing (instead of on-hold), BUT the content of the bank details is sent in the processing mail (instead of where it’s usually sent in the on-hold mail)My way of getting it to work, was by adding this in functions.php of my child theme:
remove_filter( 'woocommerce_payment_gateways', 'core_gateways' ); add_filter( 'woocommerce_payment_gateways', 'my_core_gateways' ); function my_core_gateways($methods) { foreach ($methods as &$method){ if($method == 'WC_Gateway_BACS') { $method = 'WC_Gateway_BACS_custom'; } } return $methods; } /* custom gateway processor for BACS */ class WC_Gateway_BACS_custom extends WC_Gateway_BACS { public function email_instructions( $order, $sent_to_admin, $plain_text = false ) { if ( ! $sent_to_admin && 'bacs' === $order->payment_method && $order->has_status( 'processing' ) ) { if ( $this->instructions ) { echo wpautop( wptexturize( $this->instructions ) ) . PHP_EOL; } /* dirty hack to get access to bank_details */ $reflector = new ReflectionObject($this); $method = $reflector->getMethod('bank_details'); $method->setAccessible(true); $result = $method->invoke($this, $order->id); } } public function process_payment( $order_id ) { $order = wc_get_order( $order_id ); // Mark as on-hold (we're awaiting the payment) $order->update_status( 'processing', __( 'Awaiting BACS payment', 'woocommerce' ) ); // Reduce stock levels $order->reduce_order_stock(); // Remove cart WC()->cart->empty_cart(); // Return thankyou redirect return array( 'result' => 'success', 'redirect' => $this->get_return_url( $order ) ); } }I’ve seen another way to immediately move from state on-hold to processing via an action, like
https://stackoverflow.com/questions/36597663/woocommerce-change-order-status-bacs-processing – but this doesn’t solve my issue of adding a chunk to the mail.Any ideas?
The topic ‘Changing BACS workflow & mailings’ is closed to new replies.