12.2 [Woo] Action Hook: lcw_update_product_meta
This action hook allows you to add product metadata to the CRM. It provides three parameters:
$product$product_id$contact_id(CRM contact ID)
It can be done in two ways:
-
Add product 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 ); -
Add product 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_product_meta
add_action("lcw_update_product_meta", "lcw_update_product_meta_function", 10, 3);
function lcw_update_product_meta_function($product, $product_id, $contact_id){
// You will get here $product & $product_id
// With the product_id, you can retrieve your product metadata
// Add to custom field
// Arrange the product metadata in an array as key => value pairs
$fields = array(
'new_custom_field_key' => "Test value.." // The CRM 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 );
};
