function hook_commerce_google_tag_manager_line_item_data_alter in Commerce Google Tag Manager 7.2
Allow other modules to alter the Product data of a order line-item.
The $context variable is an associative array with the following keys:
- line-item : the Line item of the order
- event : the event that is requesting the product data
1 invocation of hook_commerce_google_tag_manager_line_item_data_alter()
- CommerceGoogleTagManagerHelper::getLineItemData in includes/
CommerceGoogleTagManagerHelper.php - Gets an array-based representation of the given Line Item.
File
- ./
commerce_google_tag_manager.api.php, line 15 - Documentation of Commerce GoogleTagManager hooks.
Code
function hook_commerce_google_tag_manager_line_item_data_alter(&$product_data, $context) {
// If we're sending the Checkout event
if ($context['event'] == 'checkout') {
// Overwrite the category with the product title
$product_data['category'] = $context['line-item']->commerce_product->title
->value();
}
}