12.1 [Woo] Action Hook: lcw_update_order_meta

Estimated reading: 2 minutes 41 views

This action hook allows you to add order metadata to the CRM. It provides three parameters:

  1. $order
  2. $order_id
  3. $contact_id (CRM contact ID)

It can be done in two ways:

  1. Add order metadata to the contact custom fields:To do this, use the function lcw_update_contact_fields(), passing an array of your custom field keys with their respective values.

    $fields = array(
    'new_custom_field_key' => "Test value.." // The CRM keys are {{contact.new_custom_field_key}}
    );
    lcw_update_contact_fields( $contact_id, $fields );

  2. Add order metadata as a note:To do this, use the function lcw_create_contact_note(), passing the note you want to add to the contact.

    $note = "This is a new note!";
    lcw_create_contact_note( $contact_id, $note );

To implement this hook, here’s an example:


// How to use action hook: lcw_update_order_meta

add_action("lcw_update_order_meta", "lcw_sync_order_meta_function", 10, 3);
function lcw_sync_order_meta_function($order, $order_id, $contact_id){
    
    // You will get here $order & $order_id
    // With the order_id, you can retrieve your order meta data
    
    // Add to custom field
    // Arrange the order meta data in an array as key => value pair, 

    $fields = array(
 	'new_custom_field_key' => "Test value.." // the GHL keys are {{contact.new_custom_field_key}}
    );
    
    // Run the function
    lcw_update_contact_fields( $contact_id, $fields );
    
    // Add as a contact note
    $note = "This is a new note!";
    lcw_create_contact_note( $contact_id, $note );

};

Leave a Reply

Your email address will not be published. Required fields are marked *

Share this Doc

12.1 [Woo] Action Hook: lcw_update_order_meta

Or copy link

CONTENTS