Viewing 9 replies - 1 through 9 (of 9 total)
  • Hi,

    Have a look at WunderAutomation (free on the www.ads-software.com repo) combined with the MailChimp add-on (premium). It will let you update MailChimp contacts based on user or order data.

    It depends a little bit on how you collect the additional fields at checkout, but I’m assuming the birthday is either stored on the order object or a user object?

    Thread Starter stefk

    (@stefk)

    Thank you for the feedback. I will take a look at the plugin as a last resort.

    Was hoping to pass on the data natively, even with a function.

    We have stored the data as both, order and user object.

    Plugin Author ryanhungate

    (@ryanhungate)

    @stefk have you taken a look at our GitHub wiki? This shows you exactly how to add in custom fields during a user sync.

    We’re also going to be releasing the next version 2.4.2 fairly soon which will also have another hook to filter the merge tags with the order itself – using a filter called mailchimp_get_ecommerce_merge_tags. This will be documented very shortly after release. For right now, you may use the link above which passes in the user object.

    Also – just because I noticed it while looking at the links you sent – one of them is referencing a completely different plugin ( MC4Woo ). This is NOT our plugin – we are Mailchimp for WooCommerce – the official one.

    If you have any questions after looking at our wiki – please feel free to reach back out – more than happy to help.

    Hi I have a similar problem. Based on your link to the wiki, i have the following function added:

    function custom_mailchimp_sync_user_mergetags($merge_vars, $user) {
    	$merge_vars['TROUWDATUM'] = 'tryout';
    
    	return $merge_vars;
    
    }
    add_filter('mailchimp_sync_user_mergetags', 'custom_mailchimp_sync_user_mergetags', 100, 2);

    In the log, i see the information is not sended .

    However, when i change the function to:

    
    function custom_mailchimp_sync_user_mergetags($merge_fields, $user) {
    	/// add anything you would like to this array - and return it
    	$merge_fields['TROUWDATUM'] = 'tryout';
    
    	return $merge_fields;
    
    }
    add_filter('mailchimp_sync_user_mergetags', 'custom_mailchimp_sync_user_mergetags', 10, 2);

    The information is sended, i see in the logs.

    but then the information is not imported in mailchimp. I created a custom field in mailchimp with “Trouwdatum” and for testing purposes set it on text.

    What is going wrong here?

    Thread Starter stefk

    (@stefk)

    Having the same issue as you Kees78

    Hi @stefk, I posted a new topic on the forum, see https://www.ads-software.com/support/topic/custom-fields-not-syncing-2/.
    So now waiting for an answer…

    Plugin Author ryanhungate

    (@ryanhungate)

    @stefk as we had said previously – when the next version 2.4.2 comes out you’ll be able into the mailchimp_get_ecommerce_merge_tags function which is tied directly to the ecommerce customer submission process, and that might be all you needed here.

    The user hook only submits merge tags for subscribed users. Otherwise nothing will happen. The new hook will be available shortly and we will post here when it’s released. @kees78 same thing for you as well on this reply. ??

    Thread Starter stefk

    (@stefk)

    @ryanhungate
    We have updated the plugin. Its working only when I have a hardcoded value on the merge tag. We are trying to add a date custom field using the date picker. Below is the code we added to functions.php and comments included. This is working properly. The date you can see it in the backend saved. For some reason, this code is failing to get the submitted value. What am I doing wrong?

    /**
    * Add custom field to the checkout page
    */
    
    add_action('woocommerce_after_order_notes', 'custom_checkout_field');
    
    function custom_checkout_field( $checkout ){
    
     
    
    echo '<div id="date-of-birth-field"><h2>' . __('Date of Birth') . '</h2>';
    
     
    
        woocommerce_form_field( 'date_of_birth', array(
            'type'          => 'date',
            'class'         => array('my-dateofbirth-class form-row-wide'),
            'label'         => __('Fill in this field'),
            'placeholder'   => __('DD/MM'),
            ), $checkout->get_value( 'date_of_birth' ));
    
     
    
        echo '</div>';
    }
    
     
    
    /**
    * Checkout Process
    */
    add_action('woocommerce_checkout_process', 'customised_checkout_field_process');
    function customised_checkout_field_process(){
    
     
    
    // Show an error message if the field is not set.
    
     
    
    if (!$_POST['date_of_birth']) wc_add_notice(__('Please enter date of birth!') , 'error');
    
     
    
    }
    
     
    
    /**
    * Save the value given in custom field
    */
    add_action('woocommerce_checkout_update_order_meta', 'custom_checkout_field_update_order_meta');
    function custom_checkout_field_update_order_meta($order_id){
    
     
    
        if (!empty($_POST['date_of_birth'])) {
        //convert the submitted date so that we get only MM/DD as the Mailchimp set date format
            $date = new DateTime($_POST['date_of_birth']);
            $birthday = $date->format('d/m');
    
     
    
            update_post_meta($order_id, 'Date of Birth', $birthday);
    
     
    
        }
    
     
    
    }
    
     
    
    /**
     * @param array $merge_tags
     * @param MailChimp_WooCommerce_Order $order
     * @return array
     */
    function mailchimp_custom_order_merge_tags($merge_tags, $order, $order_id) {
    
     
    
        $birthday = get_post_meta( $order_id, '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);

    @stefk

    It should work with:

    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 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Birthdate Field’ is closed to new replies.