Reputation: 1
I am trying to send Google Merchant an ACF (Advanced Custom Fields Plugin) field – ‘isbn’ – and map it as the ‘GTIN’ attribute through the ‘Google Listings and Ads’ plugin in WordPress. I want to use some custom php in a Code Snippet to do this so I don't have to worry about Child Themes.
The reason I want this functionality is because my client updates their ISBN on their products with an ACF field in order for it to also get displayed on the front-end. I need to keep it simple for them so they aren’t updating the same value in multiple places.
So therefore I need a way for Google Listings and Ads to 'understand' the ACF field and map it to GTIN.
I found this article here which suggests it is possible to map custom fields to the plugin and then assign an attribute like GTIN to them.
That article tells me to use the following code:
add_filter(
'woocommerce_gla_attribute_mapping_sources_custom_attributes',
function( $values ) {
return array_merge( $values, ['isbn']);
}
);
This made the field show up in the Google plugin, but this field wasn't actually the ACF field I needed, it was just a random made up value also called - 'isbn'.
I need it to specifically be the ACF field – ‘isbn’ – so that it transmits this data to Google Merchant correctly.
Basically something like this:
add_filter(
'woocommerce_gla_attribute_mapping_sources_custom_attributes',
function( $values ) {
$variable = get_field('isbn');
return array_merge( $values, [$variable]);
}
);
Perhaps I need to push the value into this array somehow? I’m not much into php beyond the basics sorry but I have tried looking extensively for a solution to this with no avail.
Anyone have any thoughts or experience with this?
It would be much appreciated, thanks.
Upvotes: 0
Views: 58