Created
August 28, 2023 13:49
-
-
Save amirhmoradi/a9faf8102cbc61a86e270d377500cd53 to your computer and use it in GitHub Desktop.
Woocommerce Brands Add Product Brand to Woocommerce Google Analytics Pro data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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