id = 'bacs'; $this->icon = apply_filters('woocommerce_bacs_icon', ''); $this->has_fields = false; $this->method_title = __( 'BACS', 'woocommerce' ); $this->method_description = __( 'Allows payments by BACS, more commonly known as direct bank/wire transfer.', 'woocommerce' ); // Load the settings. $this->init_form_fields(); $this->init_settings(); // Define user set variables $this->title = $this->get_option( 'title' ); $this->description = $this->get_option( 'description' ); $this->instructions = $this->get_option( 'instructions', $this->description ); // BACS account fields shown on the thanks page and in emails $this->account_details = get_option( 'woocommerce_bacs_accounts', array( array( 'account_name' => $this->get_option( 'account_name' ), 'account_number' => $this->get_option( 'account_number' ), 'sort_code' => $this->get_option( 'sort_code' ), 'bank_name' => $this->get_option( 'bank_name' ), 'iban' => $this->get_option( 'iban' ), 'bic' => $this->get_option( 'bic' ) ) ) ); // Actions add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'save_account_details' ) ); add_action( 'woocommerce_thankyou_bacs', array( $this, 'thankyou_page' ) ); // Customer Emails add_action( 'woocommerce_email_before_order_table', array( $this, 'email_instructions' ), 10, 2 ); } /** * Initialise Gateway Settings Form Fields */ public function init_form_fields() { $this->form_fields = array( 'enabled' => array( 'title' => __( 'Enable/Disable', 'woocommerce' ), 'type' => 'checkbox', 'label' => __( 'Enable Bank Transfer', 'woocommerce' ), 'default' => 'yes' ), 'title' => array( 'title' => __( 'Title', 'woocommerce' ), 'type' => 'text', 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce' ), 'default' => __( 'Direct Bank Transfer', 'woocommerce' ), 'desc_tip' => true, ), 'description' => array( 'title' => __( 'Description', 'woocommerce' ), 'type' => 'textarea', 'description' => __( 'Payment method description that the customer will see on your checkout.', 'woocommerce' ), 'default' => __( 'Make your payment directly into our bank account. Please use your Order ID as the payment reference. Your order won\'t be shipped until the funds have cleared in our account.', 'woocommerce' ), 'desc_tip' => true, ), 'instructions' => array( 'title' => __( 'Instructions', 'woocommerce' ), 'type' => 'textarea', 'description' => __( 'Instructions that will be added to the thank you page and emails.', 'woocommerce' ), 'default' => '', 'desc_tip' => true, ), 'account_details' => array( 'type' => 'account_details' ), ); } /** * generate_account_details_html function. */ public function generate_account_details_html() { ob_start(); ?> : account_details ) { foreach ( $this->account_details as $account ) { $i++; echo ''; } } ?>
 
$name ) { if ( ! isset( $account_names[ $i ] ) ) continue; $accounts[] = array( 'account_name' => $account_names[ $i ], 'account_number' => $account_numbers[ $i ], 'bank_name' => $bank_names[ $i ], 'sort_code' => $sort_codes[ $i ], 'iban' => $ibans[ $i ], 'bic' => $bics[ $i ] ); } } update_option( 'woocommerce_bacs_accounts', $accounts ); } /** * Output for the order received page. */ public function thankyou_page( $order_id ) { if ( $this->instructions ) echo wpautop( wptexturize( wp_kses_post( $this->instructions ) ) ); $this->bank_details( $order_id ); } /** * Add content to the WC emails. * * @access public * @param WC_Order $order * @param bool $sent_to_admin * @return void */ public function email_instructions( $order, $sent_to_admin ) { if ( $sent_to_admin || $order->status !== 'on-hold' || $order->payment_method !== 'bacs' ) return; if ( $this->instructions ) echo wpautop( wptexturize( $this->instructions ) ); $this->bank_details( $order->id ); } /** * Get bank details and place into a list format */ private function bank_details( $order_id = '' ) { if ( empty( $this->account_details ) ) return; echo '

' . __( 'Our Bank Details', 'woocommerce' ) . '

'; $bacs_accounts = apply_filters( 'woocommerce_bacs_accounts', $this->account_details ); if ( ! empty( $bacs_accounts ) ) { foreach ( $bacs_accounts as $bacs_account ) { echo ''; } } } /** * Process the payment and return the result * * @param int $order_id * @return array */ public function process_payment( $order_id ) { $order = new WC_Order( $order_id ); // Mark as on-hold (we're awaiting the payment) $order->update_status( 'on-hold', __( '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 ) ); } }