Product description
-
Hi,
Is it possible to change product description in my feed with meta description or excerpt?
Thank you
-
Hi,
Firstly, I added a quick way to do it with a custom code in the 2.0.1 plugin version that I just released.
So, make sure to update the plugin to latest version. Then, you can do it with a custom code to add to your website (in functions.php of your theme or as a new plugin). Here the code:
add_filter( 'aepc_feed_item', function( $fields, FeedMapper $item ) { $fields['g:description'] = get_the_excerpt( $item->get_id() ); // or... $fields['g:description'] = get_post_meta( $item->get_id(), '_your_meta_description', true ); return $fields; }, 10, 2 );This is an example. Adjust it as you want exactly, leaving one of the two
$fields['g:description']lines and, in case you need to get the value from a post meta (so, second line), change that_your_meta_descriptionwith the exact meta name.I hope that can help you.
Let me know.Hi,
I added the following to my child theme’s functions.php:add_filter( ‘aepc_feed_item’, function( $fields, FeedMapper $item ) {
$fields[‘g:description’] = get_the_excerpt( $item->get_id() );
return $fields;
}, 10, 2 );and the error is:
Argument 2 passed to {closure}() must be an instance of FeedMapper, instance of PixelCaffeine\ProductCatalog\FeedMapper given, called in ***/wp-includes/class-wp-hook.php on line 286
Hi,
sorry, replace the first line of previous code with:
add_filter( 'aepc_feed_item', function( $fields, PixelCaffeine\ProductCatalog\FeedMapper $item ) {Hi,
I added:
add_filter( ‘aepc_feed_item’, function( $fields, PixelCaffeine\ProductCatalog\FeedMapper $item ) {
$fields[‘g:description’] = get_the_excerpt( $item->get_id() );
return $fields;
}, 10, 2 );but no description:
<g:description><![CDATA[]]></g:description>
Okay sorry, use this code (I was able to test now and it works great on my end):
add_filter( 'aepc_feed_item', function( $fields, PixelCaffeine\ProductCatalog\FeedMapper $item ) { $post = get_post( $item->get_id() ); $fields['g:description'] = $post->post_excerpt; return $fields; }, 10, 2 );It should work now, but anyway, I just discovered that if some product doesn’t have the main description defined, the feed saving process will show an error (because the description is required inside the feed), even if you have changed the description value source through the previous code.
So, if it’s your case, I ask you to download the plugin from the following URL, where I added some other filters before the exception will throw, in order to fix this annoying problem: https://www.dropbox.com/s/nxwz7ib93y6wxzj/pixel-caffeine.2.0.1.hooks.zip?dl=1 (this fix will be available on next version, so you won’t do anything to keep the fix)
After downloaded, replace the plugin with the one you have on your website and use this code instead of previous:
add_filter( 'aepc_feed_item_description', function( $description, PixelCaffeine\ProductCatalog\FeedMapper $item ) { $post = get_post( $item->get_id() ); $description = $post->post_excerpt; return $description; }, 10, 2 );Note that in this way all products must have an excerpt defined, otherwise the saving process will show you an error.
Hi,
The link is broken, I can’t download.Could you please try again? https://www.dropbox.com/s/nxwz7ib93y6wxzj/pixel-caffeine.2.0.1.hooks.zip?dl=0
It works great to me.
Broken archive, can’t open zip file
its ok now will try
Really strange, I can download and open it without any problem, even if incognito mode.
Please, try from here: https://www.justbeamit.com/875g2
error: the field “description” in must not be empty.
It’s the thing I told you previously:
Note that in this way all products must have an excerpt defined, otherwise the saving process will show you an error.
Most probably some product doesn’t have an excerpt (in your case). Make sure all items return a value from the previous code.
but it worked in “Woocommerce Google product feed” with the code:
function lw_woocommerce_gpf_description( $description, $product_id, $variation_id = null ) {
global $post;
if ( ! is_null( $variation_id ) ) {
$ID = $variation_id;
} else {
$ID = $product_id;
}
$save_post = $post;
$post = get_post( $ID );
if ( ! empty( $post->post_parent ) ) {
$post = get_post( $post->post_parent );
}
setup_postdata( $post );
$excerpt = get_the_excerpt();
$post = $save_post;
return $excerpt;
}
add_filter( ‘woocommerce_gpf_description’, ‘lw_woocommerce_gpf_description’, 10, 3 );Try in this way:
add_filter( 'aepc_feed_item_description', function( $description, PixelCaffeine\ProductCatalog\FeedMapper $item ) { $post = get_post( $item->get_id() ); if ( ! empty( $post->post_excerpt ) ) { $description = $post->post_excerpt; } return $description; }, 10, 2 );With this, if the excerpt is empty in some product, it gets the post content. In this way, all items will have a content and no error will come out.
Try and let me know.it gives full description
The topic ‘Product description’ is closed to new replies.