• Resolved mauryuplevelmarketing

    (@mauryuplevelmarketing)


    Hi!
    I’m trying to add a custom birthday field to my checkout page from Woocommerce, and at the same time I’m trying to add this data into Mailchimp so I can make a birthday automation.

    I did manage to show an extra field in my checkout page where I can add my birthday. However, when placing an order I find the label ‘Geboortedatum’ (dutch for Birthday) in my order information in Woocommerce, however, only the label and not the birthday itself. Besides that I don’t see any information back in Mailchimp audience contact (I did synchronize information about the order, so I see my order and order amount etc in Mailchimp, just nothing about the birthday).

    This is the code I used, I have no idea what is going wrong.. Hope someone can help me!

    // Hook in add date of birth in checkout field
    add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
    // Our hooked in function – $fields is passed via the filter!
    function custom_override_checkout_fields( $fields ) {
         $fields['billing']['billing_date_of_birth'] = array(
    		 'type'		=> 'date',
            'label'     => __('Geboortedatum'.'<br>'.'<small>Laat je verassen op je verjaardag!</small>', 'woocommerce'),
        'placeholder'   => _x('Geboortedatum', 'placeholder', 'woocommerce'),
        'required'  => false,
        'class'     => array('form-row-wide'),
        'clear'     => true
         );
         return $fields;
    }
    /**
     * Display field value on the order edit page
     */
    add_action( 'woocommerce_admin_order_data_after_billing_address', 'my_custom_checkout_field_display_admin_order_meta', 10, 1 );
    function my_custom_checkout_field_display_admin_order_meta($order){
        echo '<p><strong>'.__('Geboortedatum').':</strong> ' . get_post_meta( $order->get_id(), 'date_of_birth', true ) . '</p>';
    }
    
    
    
    function mailchimp_custom_order_merge_tags($merge_tags, $order) {
    
        $birthday = get_post_meta( $order->getId(), 'date_of_birth', true );
        /// add whatever you want to the merge tags
        $merge_tags['MMERGE3'] = $birthday;
    
        return $merge_tags;
    }
    
    add_filter('mailchimp_get_ecommerce_merge_tags', 'mailchimp_custom_order_merge_tags', 10, 2);
Viewing 1 replies (of 1 total)
  • Plugin Support khungate

    (@khungate)

    Hi @mauryuplevelmarketing,

    Thanks for contacting us about the custom birthday field. Upon investigating, it seems the birthday value is not getting saved to the order metadata on checkout. So when you try to retrieve it later, it comes back empty.

    To fix this, you’ll need to hook into an action like woocommerce_checkout_update_order_meta to save the birthday field to the order metadata when the order is created.

    Additionally, I’d suggest using a unique merge tag key instead of MMERGE3, as that may conflict with other plugins. Something like CUSTOMER_BIRTHDAY would be more unique.

    The main steps would be:

    1. Save the birthday value to order metadata on checkout
    2. Retrieve the saved value when setting up merge tags
    3. Use a unique merge tag key

    Once you have the birthday value saving properly, the next step would be getting it to output correctly in Mailchimp. But let’s focus first on getting it stored properly on checkout.

    Let me know if any part of the process needs clarification or if you have any other questions!

Viewing 1 replies (of 1 total)
  • The topic ‘Adding birthday field to Mailchimp’ is closed to new replies.