• Resolved zoonars

    (@zoonars)


    Hello team,

    I’ve been struggling to figure out how to send additional meta data to Mailchimp from my WooCommerce transactions. Basically for every WooCommerce order that I produce, I enter a custom field/meta that indicates when the order is due (meta it called ‘order_due’ saved as MM/DD/YYYY) that I would like to pass to Mailchimp. I’ve found and reviewed older threads of people asking the similar questions, and even found a Wiki on how to do it; yet, I am still unsuccessful.

    https://github.com/mailchimp/mc-woocommerce/wiki/Custom-Merge-Tags

    I am hoping it is something very obvious like an incorrect hook, but here is what I have so far. Please also let me know if my syntax is okay since I’m not very PHP savvy.

    > In Mailchimp I’ve added a new merge Date Field with the ORDERDATE tag name.

    > Here is my current code snippet that I am trying to print to the Mailchimp log but not getting anything. I’m trying to get the post ID and from there grab the specific meta info and pass it to Mailchimp.

    // Pass Order Due meta to Mailchimp
    add_filter('mailchimp_sync_user_mergetags', 'custom_user_merge_tags', 10, 2);
    
    // Mailchimp custom merge tags
    function custom_user_merge_tags($merge_vars, $order) {
    	$orderDue = get_post_meta( $order->get_id(), 'order_due', true );
    	$merge_vars['ORDERDATE'] = $orderDue ;
    	
    	mailchimp_log('trace', 'custom_fields', $merge_vars);
    
    	return $merge_vars;
    }
Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter zoonars

    (@zoonars)

    I’ve been researching some more and found other threads with debugging tips. What I’ve done is created a TEST merge tag and set it to text, and with the following code snippet I do not see anything in the Mailchimp log.

    add_filter('mailchimp_sync_user_mergetags', 'woocommerce_mailchimp_extra_data', 100, 2);
    
    // Mailchimp custom merge tags
    function woocommerce_mailchimp_extra_data( $merge_tags, $order_id ) {
    	
        $merge_tags['TEST'] = 'testing';
    	
    	mailchimp_log('custom_fields', "Custom Fields", array('tags' => $merge_tags));
    
    	return $merge_tags;
    }
    • This reply was modified 3 years, 12 months ago by zoonars.
    • This reply was modified 3 years, 12 months ago by zoonars.
    Plugin Author ryanhungate

    (@ryanhungate)

    @zoonars i think you’re so close to finding your answer – but missed the correct github wiki which shows you how to tap into the “ecommerce order” push, and add a merge tag that way.

    Let us know if this is what you were after 😉

    Thread Starter zoonars

    (@zoonars)

    Thanks for correcting me on that. I made the change and saw the testing tag come through! Success!

    I wanted to confirm one more detail about the syntax for: function woocommerce_mailchimp_extra_data( $merge_tags, $order_id )

    What information is passed into the second argument placeholder ($order_id)?

    After some research I learned it is a Mailchimp_WooCommerce_Order object, and it seems the WooCommerce/WordPress methods to get post id arent working.

    I can’t seem to get the actual post/page ID to print into the mailchimp log, I’m ultimately trying to grab a meta property to pass to MailChimp.

    • This reply was modified 3 years, 11 months ago by zoonars.
    • This reply was modified 3 years, 11 months ago by zoonars.
    Plugin Author ryanhungate

    (@ryanhungate)

    @zoonars the argument passed in is the mailchimp order object yes… and you can just get the ID by calling $order->getId();

    Sorry if that wasn’t clear. The documentation shows the order object as the argument, you would just need to look into the class itself to see the methods available.

    Let us know if you have any other questions, we’ll be glad to help there.

    Thread Starter zoonars

    (@zoonars)

    From the the order ID Im trying to get a custom meta page property called ‘order_due’, and so far I have this code. Could you confirm if this syntax is correct?

    The format of ‘order_due’ is MM/DD/YYYY, so should I format the data into a string? I have already set the data format in Mailchimp to match

    
    $orderId = $order->getId();
    $orderDue = get_post_meta( $orderId, 'order_due', true );
    
    Thread Starter zoonars

    (@zoonars)

    Okay, that is the correct syntax. Thanks for all the help, this thread can be closed.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Transactional Meta Sync Issues’ is closed to new replies.