Support » Plugin: Pixel Caffeine » Custom Label
Custom Label
-
Hi,
How do you create a custom label in WordPress and get it into the feed?
We want to add a custom made text for Facebook dynamic ads per product, get this into the feed and in the ad.
How do we do this?
Thank you for your help.
-
Hi,
first off, you should know how to add this custom made text. Then, you should need to add a custom code in the
functions.php
file of your current theme (or child theme):add_filter('aepc_feed_item', function($fields, $item) { $fields['g:custom_label_0'] = get_post_meta($item['g:id']); return $fields; }, 10, 2);
In this example, I assumed that it’s a custom field of the product saved through the post metas.
If the custom text will be a woocommerce attribute, you can also replace:
get_post_meta($item['g:id'])
with
wc_get_product($item['g:id'])->get_attribute('attribute_name')
-
This reply was modified 2 years, 9 months ago by
Antonino Scarfì.
Hi Antonio,
It would be a global attribute (added in
/post_type=product&page=product_attributes
) we use calledfacebook_meta
and it has an unique value per product. Then do we still use this code in functions.php?add_filter('aepc_feed_item', function($fields, $item) { $fields['g:custom_label_0'] = wc_get_product($item['g:id'])->get_attribute('facebook_meta') return $fields; }, 10, 2);
Additionally do I need to add something to the special mapping section in Pixel caffeine?
Thank you for your help
-
This reply was modified 2 years, 8 months ago by
Dominic Heselmans.
-
This reply was modified 2 years, 8 months ago by
Dominic Heselmans.
Can you clarify this? I’m trying to do the same but am unsure how to utilise the code snippet.
My understanding is that I want to include an attribute called Size in the feed, I need to add this code:
add_filter(‘aepc_feed_item’, function($fields, $item) {
$fields[‘g:custom_label_0’] = wc_get_product($item[‘g:id’])->get_attribute(‘size’);
return $fields;
}, 10, 2);Once I have done this, I can add Size as one of the Custom labels, and it will add the Size for all products to the feed.
Is this correct?
Hi,
the snippet should be good for your case. Just add it at the end of the
functions.php
file and it should be already active. Then, refresh the feed manually and you should have the new field inside each item of the feed.Hi Antonio,
I can’t seem to get it to work.I added the code to functions.php (I use genesis extender for this)
I added a global term facebook_meta
I’ve added Facebook meta to a product
Then I refreshed the feed but the extra field facebook_meta is not showing even for that specific product.
Additionally I get a parse error when I use the following code
add_filter('aepc_feed_item', function($fields, $item) { $fields['g:custom_label_0'] = wc_get_product($item['g:id'])->get_attribute('facebook_meta') return $fields; }, 10, 2);
What am I doing wrong?
Thank you for the help
Kind regards,
Dominic-
This reply was modified 2 years, 8 months ago by
Dominic Heselmans.
-
This reply was modified 2 years, 8 months ago by
Dominic Heselmans.
Hi,
sorry for the late response.
You simply missed the final
;
in the$fields['g:custom_label_0'] = ...
line.
Here the fixed snippet:add_filter('aepc_feed_item', function($fields, $item) { $fields['g:custom_label_0'] = wc_get_product($item['g:id'])->get_attribute('facebook_meta'); return $fields; }, 10, 2);
Hi Antonio,
It’s still not showing up in the feed (I cleaned cache).
What could I be doing wrong?
Ok, sorry my fault!
I reproduced your case on my end and I fixed the code, here it is:
add_filter('aepc_feed_item', function($fields, \PixelCaffeine\ProductCatalog\FeedMapper $item) { if ($product = wc_get_product($item->get_item()->get_id())) { $fields['g:custom_label_0'] = $product->get_attribute('facebook_meta'); } return $fields; }, 10, 2);
It works for me, let me know if it’s so on your end as well 🙂
Hi Antonino,
It works!
Thank you very much for all the help 🙂
Awesome! Glad to hear this solved 🙂
If you need further help, don’t hesitate to open a new topic 🙂Also, would you take 1 minute to leave a review about your experience with Pixel Caffeine? Here’s the link. Thanks for your help!
Have a nice day!
-
This reply was modified 2 years, 9 months ago by
- The topic ‘Custom Label’ is closed to new replies.