This file contains 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 | |
// Round the price | |
function round_price( $data, $feed_id, $product_id ) { | |
// round price. | |
$round_price = round($data['price'], 2); | |
// Store the rounded price in the feed price element. | |
$data['price'] = $round_price; |
This file contains 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
Function add_attribute_to_xml_tag( $attribute_value, $xml_key, $xml_value ) { | |
if ( 'bottles' === $xml_key ) { | |
return 'size=”750 ml”'; | |
} else { | |
return $attribute_value; | |
} | |
} | |
add_filter( 'wppfm_xml_element_attribute', 'add_attribute_to_xml_tag', 10, 3 ); |
This file contains 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
// use the original description without stripping away all the line breaks and paragraph tags from the description field. | |
function use_original_description( $data, $feed_id, $product_id ) { | |
// Only use the original description in the feed with the given ID (in this case 2) | |
// remove if you want this for all feeds. | |
if($feed_id == 2 ){ | |
// Get the product. | |
$wc_product = wc_get_product( $product_id ); |
This file contains 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 ) { | |
// Strip html from description attributes | |
// allow given tags with allowedTags | |
$allowedTags = ""; | |
$attributes['description'] = strip_tags($attributes['description'], $allowedTags); | |
// IMPORTANT! Always return the $attributes |
This file contains 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
/** | |
* Create clean description attribute by removing html, VC en DIVI markup etc. | |
* @param array $attributes variable is an array that contains all the product data that goes into the feed. | |
* @param Int $feed_id makes it possible to only edit a specific feed. You can find the id of a feed in the url of the Feed Editor | |
* @param Int $product_id makes it possible to select a specific product id that you want to filter. | |
* @return array. | |
*/ | |
function alter_feed_description_item( $attributes, $feed_id, $product_id ) { | |
// Remove WordPress shortcodes from Description |
This file contains 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
/** | |
* Use parent description for product variations | |
*/ | |
function use_parent_description_for_product_variations( $data, $feed_id, $product_id ) { | |
$wc_product = wc_get_product( $product_id ); | |
if ( $wc_product && ( $wc_product instanceof WC_Product_Variation || $wc_product instanceof WC_Product_Variable ) ) { | |
$parent_id = $wc_product->get_parent_id( 'feed' ); | |
$wc_parent = wc_get_product( $parent_id ); |
This file contains 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
/** | |
* Alter Product feed item | |
* remove multiple characters from attribute | |
*/ | |
function alter_feed_description_attribute( $attributes, $feed_id, $product_id ) { | |
global $product; | |
// Remove multiple characters from attribute | |
$remove = [",", ":", ";"]; | |
$attributes['description'] = str_replace($remove, '', $attributes['description']); |
This file contains 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
function expand_cdata_attributes( $cdata_attributes ) { | |
// price and availability attributes are added to the list of attributes that are included in a CDATA bracket | |
array_push( $cdata_attributes, 'price', 'availability' ); | |
return $cdata_attributes; | |
} | |
add_filter( 'wppfm_cdata_keys', 'expand_cdata_attributes' ); |
This file contains 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 | |
// Locate the file header.php in your theme | |
// Before editing header.php, always make a backup so that you can roll back if something goes wrong. | |
// At the bottom of the header, simple add the code below | |
// Verify that you have done it correctly by checking the page with Google’s Structured Data Testing Tool | |
// https://search.google.com/structured-data/testing-tool | |
if (isset($product)){ | |
$meta = get_post_meta(get_the_ID()); | |
$_product = new WC_Product(get_the_ID()); | |
if ($_product->regular_price!=NULL){ |
This file contains 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_price_item_remove_thousand_seperator( $attributes, $feed_id, $product_id ) { | |
global $product; | |
$product = wc_get_product( $product_id ); | |
$product_price = $attributes['price']; | |
// show price without thousand separator and . as decimal separator | |
$attributes['price'] = number_format( $product_price, 2, '.', '') . " EUR"; | |
// price will look like 1234.57 |