Skip to content

Instantly share code, notes, and snippets.

@Auke1810
Last active August 3, 2018 11:26
Show Gist options
  • Save Auke1810/df975590ff5c841c792580bb5d176c26 to your computer and use it in GitHub Desktop.
Save Auke1810/df975590ff5c841c792580bb5d176c26 to your computer and use it in GitHub Desktop.
Convert Attribute to Uppercase
<?php
/**
* Alter Product feed item
* Uppercase a source value (attribute_pa_cup) and combine with an other source value in the size attribute
*/
function alter_feed_item( $attributes, $feed_id, $product_id ) {
// get values
$attribute_pa_band = $attributes['custom_label_0']; //add the attribute_pa_band to attribute "custom_label_0"
$attribute_pa_cup = $attributes['custom_label_1']; //add the attribute_pa_cup to attribute "custom_label_1"
// uppercase attribute_pa_cup
$attribute_pa_cup = strtoupper($attribute_pa_cup); //make upper case
//combine and add to the size attribute BUT only if custom_label_0 and custom_label_1 contain values.
if( !empty($attributes['custom_label_0'] ) && !empty($attributes['custom_label_1'] ) ){
$attributes['size'] = $attribute_pa_band . " " . $attribute_pa_cup;
}
// IMPORTANT! Always return the $attributes
return $attributes;
}
add_filter( 'wppfm_feed_item_value', 'alter_feed_item', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment