Skip to content

Custom Order Alteration Hook

khungate edited this page Jul 25, 2023 · 4 revisions

Welcome to the guide on using the Custom Order Alteration Hook in the MailChimp for WooCommerce Integration. This guide is designed to assist store owners who need to utilize custom order statuses and financial statuses to activate MailChimp Automations.

Overview

Functionality

The Custom Order Alteration Hook allows you to modify the order details just before they are submitted. This is a powerful feature but it's also advanced, so we recommend testing it in a development or staging environment before deploying it in a live setting.

Code Example

Basic Usage

Below is a basic example of how to use this function. Please note that this is a starting point and you should tailor the function to meet your specific needs.

/**
 * This function modifies the order status if it's 'on-hold'.
 * It sets the status to 'processing' and the financial status to 'pending'.
 *
 * @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);

Next Steps

Monitoring and Error Handling

After implementing this function, you should monitor your orders to ensure they are being processed correctly. If you encounter any issues, consider adding error handling to your function to manage potential problems.