Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save amirhmoradi/a9faf8102cbc61a86e270d377500cd53 to your computer and use it in GitHub Desktop.
Save amirhmoradi/a9faf8102cbc61a86e270d377500cd53 to your computer and use it in GitHub Desktop.
Woocommerce Brands Add Product Brand to Woocommerce Google Analytics Pro data
<?php
// Add product brand to Woocommerce google analytics pro plugin
function ax_wc_gapro_add_product_brand($aProduct=[]){
if(empty($aProduct['brand'])){
$iProductId = wc_get_product_id_by_sku($aProduct['id']);
$aProduct['brand'] = implode(', ', wp_get_post_terms($iProductId, 'product_brand', ['fields' => 'names']));
}
return $aProduct;
}
add_filter( 'wc_google_analytics_pro_product_details_data', 'ax_wc_gapro_add_product_brand', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment