Last active
October 2, 2019 19:23
-
-
Save Auke1810/c62bb043926f539f9a99b418c06a3e6e to your computer and use it in GitHub Desktop.
Example how to use the wppfm_feed_item_value filter for woocommerce product feed manager
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 | |
function alter_feed_item( $attributes, $feed_id, $product_id ) { | |
// The $attributes variable is an array that contains all the product data that goes into the feed. Each item | |
// can be accessed by it's feed key. So if in the feed file an item has a key like 'description', you | |
// can access that specific item by $attributes['description']. | |
// The $feed_id (string) makes it possible to only edit a specific feed. You can find the id of a feed in the | |
// url of the Feed Editor, right after id=. | |
// The $product_id (string) makes it possible to select a specific product id that you want to filter. | |
// The following example only changes the data of a feed with ID 7 | |
if( $feed_id === '7' ) { | |
// this line changes the title data and removes the " <prompt> " string | |
$attributes['title'] = str_replace( " <prompt> ", "", $attributes['title'] ); | |
// this lines puts the text Dollar behind the price data | |
$attributes['price'] = $attributes['price'] . " Dollar"; | |
// And you can be more specific by using the $product_id | |
if ( $product_id === '13' ) { | |
$attributes['availability'] = 'unknown'; | |
} | |
} | |
// or you can just make a simple change that will influence all feeds | |
// If you have shortcodes in your product description you can remove them with het next code | |
// Remove WordPress shortcodes from Description | |
$attributes['description'] = strip_shortcodes( $attributes['description'] ); | |
// If you use Visual Composer markup in your product descrioptions you can remove Visual Composer markup with the next code. | |
$attributes['description'] = preg_replace("/\[(\/*)?vc_(.*?)\]/", '', $attributes['description'] ); | |
// To remove Divi markup in your product description use the below preg replace. | |
$attributes['description'] = preg_replace("/\[\/?et_pb.*?\]/", '', $attributes['description'] ); | |
// IMPORTANT! Always return the $attributes | |
return $attributes; | |
} | |
add_filter( 'wppfm_feed_item_value', 'alter_feed_item', 10, 3 ); |
@Auke1810 does this overwrite settings from within plugin? (Hopefully)
If you’re not familiar with using filters in your wp-admin, the best and easiest way to do this is by using the “My Custom Functions” plugin (https://wordpress.org/plugins/my-custom-functions/). And here you can find a great video explaining the use if this plugin https://www.youtube.com/watch?v=R8dZ-mSRNOg.
@Auke1810 does this overwrite settings from within plugin? (Hopefully)
Not fully understand what your asking. The function alters the feed and feed settings after the settings in the plugin. So if you set the price in a certain way in the feed settings this filter will alter it again.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The $attributes variable is an array that contains all the product data that goes into the feed. Each item can be accessed by it's feed key. So if in the feed file an item has a key like 'description', you can access that specific item by $attributes['description']. The $feed_id (string) makes it possible to only edit a specific feed. You can find the id of a feed in the url of the Feed Editor, right after id=. The $product_id (string) makes it possible to select a specific product id that you want to filter.