• Resolved dmandos

    (@dmandos)


    Looking for best way to code a workflow change for notifications.

    Site is a wholesale website where orders are placed first (with no payment) and then paid later after order is confirmed/adjusted by site owner.
    The problem & question i have are at the bottom.

    Here is the process:
    1. Customer places order, they are only give payment method of “Order”. (i am using Invoice Gateway For WooCommerce plugin to register order without payment) and I hide payment method at the order stage.

    Here is code to only allow “place order” and hide Elavon payment gateway

    function my_switch_gateways_by_context($available_gateways) {
      global $woocommerce;
    
      $endpoint = $woocommerce->query->get_current_endpoint();
    
      if ($endpoint == 'order-pay') {
        unset($available_gateways['igfw_invoice_gateway']);
      } else {
        unset($available_gateways['elavon_converge_credit_card']);
      }
      return $available_gateways;
    }

    Order status goes to “processing” and New Order email is triggered to Admin and Customer.

    2. Site owner logs in, puts order On-Hold while they edit inventory counts, add shipping costs, recalculates. On-Hold email is triggered to Customer.

    3. Once order is ready for payment, Site owner changes status to “Payment Pending” to get customer to pay now. Site owner also has to manually select “email invoice order details to customer”. Invoice email is triggered to Customer with pay now link.

    4. Customer logs in to pay. We have Elavon Converge payment gateway for Credit Card processing setup. Payment is successful. We have code so that it auto changes order status to Complete when payment type is Credit Card. Here is the code for auto-complete orders paid by credit card:

    // Update order status based on the id of payment gateway
    function credit_card_complete_order_status( $order_id ) {
    	$order = new WC_Order( $order_id );
    	
        if ( $order->payment_method == 'elavon_converge_credit_card' )  {
          $order->update_status('completed', 'Automatically Completed');
        }
    }
    add_action( 'woocommerce_payment_complete', 'credit_card_complete_order_status' );

    – The order status goes from “Pending” to “completed” automatically. Complete email is triggered to Customer.

    I also have a trigger to send a copy of the completed order to site owner so that they know payment was successful as there is trigger from Elavon if successful. Here is code for BCC to admin of completed order:

    /**
     * @snippet       Add Cc: or Bcc: Recipient @ WooCommerce Completed Order Email
     * @how-to        Get CustomizeWoo.com FREE
     * @author        Rodolfo Melogli
     * @compatible    WooCommerce 3.8
     * @donate $9     https://businessbloomer.com/bloomer-armada/
     */
     
    add_filter( 'woocommerce_email_headers', 'bbloomer_order_completed_email_add_cc_bcc', 9999, 3 );
     
    function bbloomer_order_completed_email_add_cc_bcc( $headers, $email_id, $order ) {
        if ( 'customer_completed_order' == $email_id ) {         
            $headers .= "Bcc: Company Name <email@XXXXXX.com>" . "\r\n"; // del if not needed
        }
        return $headers;
    }


    PROBLEM AND QUESTION

    It also triggers “New Order” email again to customer and Admin. I assume because the code sates to change status to “complete” that maybe for a split second it goes to “processing”. Is there a way to put a code in so that emails are NOT triggered if payment type is “Credit Card”.

    Everything seems to work fine, with the exception that it triggers New Order email to both the customer and admin a second time, which is confusing. Can we eliminate this second notification?

    Here is some code i found and tried but was not successful. Any help would be appreciated.

    /**
     * Unhook and remove WooCommerce default emails.
     */
    add_action( 'woocommerce_email', 'unhook_those_pesky_emails' );
    
    function unhook_those_pesky_emails( $email_class ) {
    
    		
    		// New order emails		
    		remove_action( 'woocommerce_order_status_processing_to_completed_notification', array( $email_class->emails['WC_Email_New_Order'], 'trigger' ) );						
    		
    		// Processing order emails
    		remove_action( 'woocommerce_order_status_processing_to_completed_notification', array( $email_class->emails['WC_Email_Customer_Processing_Order'], 'trigger' ) );				
    }
    • This topic was modified 5 years, 8 months ago by dmandos.
    • This topic was modified 5 years, 8 months ago by dmandos.
    • This topic was modified 5 years, 8 months ago by dmandos.
    • This topic was modified 5 years, 8 months ago by dmandos.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

The topic ‘Woocommerce Workflow and Notification triggers’ is closed to new replies.