• Resolved atheda

    (@atheda)


    Hi Michel

    In our feed we combine two attributes called attribute_pa_band and attribute_pa_cup into the Size field. Currently the latter attribute is a letter and this is output in lowercase, we’d like to change this to upper case.

    I’d appreciate your assistance with the appropriate code to accomplish this.

    Thanks

    Lorian

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Contributor Michel Jongbloed

    (@michel-jongbloed)

    Hello Lorian,

    You can use the wppfm_feed_item_value filter to do this. See https://gist.github.com/Auke1810/c62bb043926f539f9a99b418c06a3e6e for how to use this filter.

    In the filter function you could use the strtoupper() function to change the letter to upper case.

    Thread Starter atheda

    (@atheda)

    I’m struggling with the correct syntax for this to work.
    Would you be able to provide an example please?

    Thanks

    Plugin Contributor Michel Jongbloed

    (@michel-jongbloed)

    No problem, but I’m not in today and tomorrow so I please be patient until Thursday.

    Plugin Author AukeJomm

    (@aukejomm)

    Hello @atheda,

    Let me see if I can help you out so you can get started.
    I have added a GIST with a script you could use.

    GIST: Convert Attribute to Uppercase

    Add it to your functions.php

    1. In your feed add custom_label_0 and custom_label_1
    2. Add the source attribute_pa_band and attribute_pa_cup to them.

    The script will than convert attribute_pa_cup to uppercase and combine them in the size attribute.

    Test it in your setup and let me know if this is helpfull.

    Plugin Author AukeJomm

    (@aukejomm)

    Hey @atheda, have you had the change to look at the script and tried it out?!

    
    /**
     * 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
    	$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 );
    
    • This reply was modified 7 years, 10 months ago by AukeJomm.
    Thread Starter atheda

    (@atheda)

    Hi guys

    Sorry for the delay coming back to you.
    Yes this code does work, thank you. However it introduces a small problem.

    The shop sells lingerie, whilst the Bra sizes are now correct (eg 30 DD), the addition of this code means that regular sizes for other garments (Knickers, Suspender Belts etc) no longer show. Sizes for these items now appear blank in our feed.

    Is there a way to code it so that it only applies to items which exist in the ‘Bras’ category?

    Plugin Author AukeJomm

    (@aukejomm)

    Hello @atheda,

    yes, there should be a check if the custom_label_0 and custom_label_1 contain values
    SOmthing like this:

    
    <?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 );
    

    https://gist.github.com/Auke1810/df975590ff5c841c792580bb5d176c26

    Thread Starter atheda

    (@atheda)

    That works perfectly, thank you.

    Plugin Author AukeJomm

    (@aukejomm)

    Great it worked for you @atheda.
    Let me know if you have anything else.

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Convert Attribute to Uppercase’ is closed to new replies.