• Resolved henningt

    (@henningt)


    When a client is ordering via BACS, the bank information is shown twice.
    I added following script to my functions.php since I needed to set BACS on hold:

    // Remove and add filter
    remove_filter( 'woocommerce_payment_gateways', 'core_gateways' );
    add_filter( 'woocommerce_payment_gateways', 'my_core_gateways' );
    
    /**
     * core_gateways function modified.
     *
     * @access public
     * @param mixed $methods
     * @return void
     */
    function my_core_gateways( $methods ) {
        $methods[] = 'WC_Gateway_BACS_custom';
        return $methods;
    }
    
    class WC_Gateway_BACS_custom extends WC_Gateway_BACS {
    
        /**
         * Process the payment and return the result
         *
         * @access public
         * @param int $order_id
         * @return array
         */
        function process_payment( $order_id ) {
          global $woocommerce;
    
            $order = new WC_Order( $order_id );
    
            // Mark as processing (that's what we want to change!)
            $order->update_status('payment-ou', __( 'Awaiting BACS payment', 'woocommerce' ));
    
            // Reduce stock levels
            $order->reduce_order_stock();
    
            // Remove cart
            $woocommerce->cart->empty_cart();
    
            // Return thankyou redirect
            return array(
                'result'    => 'success',
                'redirect'  => $this->get_return_url( $order )
            );
        }
    
    }

    What in this code causes the bank-information to be displayed (again)?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi @henningt

    I placed your snippet into a stock Storefront theme and got the same error. This issue is caused by the fact that you class WC_Gateway_BACS_custom triggers this action twice ‘woocommerce_thankyou_bacs’. Once it’s triggered by the default WC_Gateway_BACS and then by your custom class.
    A fix would be to remove the default BACS payment method since you are already extending it.

    Here is the updated function that fixed the issue.

    function my_core_gateways( $methods ) {
    	$methods[]     = 'WC_Gateway_BACS_custom';
    	$key_of_default_BACS_payment = array_search( 'WC_Gateway_BACS', $methods );
    	unset( $methods[ $key_of_default_BACS_payment ] );
    
    	return $methods;
    }
    Thread Starter henningt

    (@henningt)

    Thank YOU! 🙂

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘BACS info shown twice’ is closed to new replies.