Support

Account

Home Forums General Issues Update ACF field when WooCommerce order status switched to “Processing” Reply To: Update ACF field when WooCommerce order status switched to “Processing”

  • I eventually solved the problem by switching hooks to woocommerce_checkout_update_order_meta
    So that it saves on order creation and not on order status processing, because it works and it also is fine for the particular usecase.

    I assume on this webhook the saving of the ACF field is only running once so the issue brought up by John doesn’t happen.

    Thank you John for your feedback and knowledge as it was invaluable for me to learn more about how ACF works! some of this stuff would have been a headache to figure out on my own.

    
    add_action( 'woocommerce_checkout_update_order_meta', 'update_product_custom_field_', 10, 1 );
    function update_product_custom_field_( $order_id ) {
        // Generate the shipping number using the order ID
        $shipping_number = 'SHIPPINGNUMBERTEST';
    
        // Update the custom field for the shipping number
        if (function_exists('update_field')) {
            update_field( 'order_shipping_number', $shipping_number, $order_id );
        }
    }