• First of all, This is a great little plugin….! Thank you.

    I have created two custom fields labelled wc_order_field_1055 and wc_order_field_3174. The fields work. I can see the data in the subsequent sales order details that are e-mailed.

    I also need to pipe these fields into MailChimp. I am using “WooCommerce MailChimp” by SaintSystems for this.

    I have some custom PHP:

    
    /************ MAILCHIMP INTEGRATION HOOKS *********/
    /*** this code is used by WooCommerce MailChimp by 
         Saint Systems to map custom fields to MailChimp. ***/
    
    /* Shortcodes are... */
    add_filter( 'ss_wc_mailchimp_subscribe_merge_tags', 'woocommerce_mailchimp_extra_data', 10, 3 );
    
    /*function for mapping is... */
    function woocommerce_mailchimp_extra_data( $merge_tags, $order_id, $email ) {
    
        // Lets grab the order
        $order = new WC_Order( $order_id );
        $parentOrCh = $order->wc_order_field_1055;
        $source = $order->wc_order_field_3174;
        $zipCode = $order->billing_postcode;
    
        $new_merge_tags = array(
            'PARENTORCH' => $parentOrCh,
            'SOURCE' => $source,
            'ZIPCODE' => $zipCode
        );
    
        // combine the two arrays
        $merge_tags = array_merge( $merge_tags, $new_merge_tags );
    
        return $merge_tags;
    }
    

    Here’s my problem, the code transfers the zipcode, but not the two other fields. I suspect I am not accessing the two custom fields properly. Note these two fields are defined in the Order Fields section.

    Question: how can I reference the two custom fields please? Thank you, kkc.

    • This topic was modified 6 years, 7 months ago by kkc17.
    • This topic was modified 6 years, 7 months ago by kkc17.
    • This topic was modified 6 years, 7 months ago by kkc17.
  • The topic ‘accessing custom fields with PHP’ is closed to new replies.