Skip to content

Custom Order Alteration Hook

Ryan Hungate edited this page Jul 28, 2020 · 4 revisions

For store owners who need to use custom order statuses and financial statuses to trigger Mailchimp automations, you can use this filter to change the order details right before submission. Please note this is a very advanced filter and should be tested in a development or staging environment before using in production.

This is a simple example of how to use this function - use at your own risk.

/**
 * @param MailChimp_WooCommerce_Order $mc
 * @param WC_Order|WC_Order_Refund $woo
 * @return MailChimp_WooCommerce_Order
 */
function mailchimp_custom_order_parser($mc, $woo) {
    if ($mc->getOriginalWooStatus() === 'on-hold') {
        $mc->setOriginalWooStatus('processing');
        $mc->flagAsIgnoreIfNotInMailchimp(false);
        $mc->setFinancialStatus('pending');
        return $mc;
    }
    return $mc;
}

add_filter('mailchimp_filter_ecommerce_order', 'mailchimp_custom_order_parser', 10, 2);