• Resolved zikosoft

    (@zikosoft)


    Hello to everyone,

    I have a problem with using WooCommerce “woocommerce_email_actions” it send me the email twice, this is the details.

    I need to have a new specific order status so I add this code to the functions.php:

    add_action( 'init', 'register_custom_post_status', 20 );
    function register_custom_post_status() {
        register_post_status( 'wc-dispatched', array(
            'label'                     => _x( 'Dispatched', 'Order status', 'woocommerce' ),
            'public'                    => true,
            'exclude_from_search'       => false,
            'show_in_admin_all_list'    => true,
            'show_in_admin_status_list' => true,
            'label_count'               => _n_noop( 'Dispatched <span class="count">(%s)</span>', 'Dispatched <span class="count">(%s)</span>', 'woocommerce' )
        ) );
    }
    
    // Adding custom status 'dispatched' to order edit pages dropdown
    add_filter( 'wc_order_statuses', 'custom_wc_order_statuses', 20, 1 );
    function custom_wc_order_statuses( $order_statuses ) {
        $order_statuses['wc-dispatched'] = _x( 'Dispatched', 'Order status', 'woocommerce' );
        return $order_statuses;
    }

    So I can see the new order status in the order page, then I created a new plugin to send an email to the customer when this new status is selected.

    This is the code of the plugin file:

    function add_dispatched_order_woocommerce_email($email_classes){
    	// include our custom email class
    	require_once( 'includes/class-wc-dispatched-order-email.php' );
    	// add the email class to the list of email classes that woocommerce loads
    	$email_classes['WC_Dispatched_Order_Email'] = new WC_Dispatched_Order_Email();
    	return $email_classes;
    }
    
    //Add the actions to Woocommerce default actions
    function add_dispatched_order_woocommerce_actions($actions){
    	$actions[] = 'woocommerce_order_status_dispatched';
    	return $actions;
    }
    
    //Check if the plugin is enabled and add this filters
    add_action('plugins_loaded', 'woocommerce_dispatched_order_email_plugin_init');
    function woocommerce_dispatched_order_email_plugin_init() {
    	add_filter('woocommerce_email_classes', 'add_dispatched_order_woocommerce_email');
    	add_filter('woocommerce_email_actions', 'add_dispatched_order_woocommerce_actions');
    }

    The email template is a 100% copy of the “customer-completed-order.php” I changed only completed by dispatched.

    Everyhting is OK but the problem is I receive two emails of the new order status when the order status is changed to “dispatched”.

    Do you have an idea to resolve this and receive only one email?

    Thanks in advance

    Best regards

    • This topic was modified 4 years, 7 months ago by zikosoft.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Mirko P.

    (@rainfallnixfig)

    Hey @zikosoft,

    Do you have an idea to resolve this and receive only one email?

    Thanks for your question.

    This forum does not cover support to custom code and any possible problems arising from using it. However, I’m going to leave this thread open for a bit to see if anyone is able to chime in to help you out.

    You can also visit the WooCommerce Facebook Community group or the #developers channel of the WooCommerce Community Slack.

    We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there and may have ideas to help you.

    Cheers!

    Mirko P.

    (@rainfallnixfig)

    Hi there,

    This thread has been inactive with no responses for a while, so I’m going to mark it as resolved now. Hopefully, the above information about developers’ channels was helpful.

    Thanks.

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

The topic ‘WooCommerce filter woocommerce_email_actions’ is closed to new replies.