Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi nanchelant,
    You can definitely add a filter to remove the USD.

    Add the following to your theme’s funcitons.php file after the opening <?php tag or before the closing ?> tag:

    function appip_single_product_filter_jkhufs( $returnval = '' ){
    	return str_replace( ' USD ', ' ', $returnval );
    }
    add_filter('appip_single_product_filter','appip_single_product_filter_jkhufs');
    
    function amazon_product_in_a_post_plugin_elements_filter_jkhufs($retarr = array()){
    	if( is_array( $retarr ) && !empty( $retarr )){
    		foreach( $retarr as $prodkey => $prodval ){
    			if( is_array( $prodval ) && !empty( $prodval ) ){
    				foreach( $prodval as $field => $value ){
    					if( $field == 'price' || $field == 'new-price' || $field == 'new price' )
    						$retarr[ $prodkey ][ $field ] = str_replace( ' USD ', ' ', $value);
    				}
    			}else{
    				if( $prodkey == 'price' || $prodkey == 'new-price' || $prodkey == 'new price' )
    					$retarr[ $prodkey ] = str_replace( ' USD ', ' ', $prodval );
    			}
    		}
    	}
    	return $retarr;
    }
    add_filter('amazon_product_in_a_post_plugin_elements_filter','amazon_product_in_a_post_plugin_elements_filter_jkhufs');

    There are two filters here actually. The first is for those using [AMAZONPRODUCTS] shortcodes or the regular product method, and the second is for the [amazon-elements] or [amazon-element] shortcodes. For thoroughness, I thought is appropriate to add both.

    Regards,
    Don

    Hi Don,

    I was looking to take advantage of this but I’m running into a problem.

    It doesn’t appear to work with “LowestNewPrice”. Thoughts?

    Thanks,

    Andrew

    Andrew,
    That is because the LowestNewPrice field does not have a space after the USD as the others do.

    Use this one – it is laid out a bit better and uses a regex to find the text instead of just a string replace:

    function amazon_product_in_a_post_plugin_elements_filter_jkhufs($retarr = array()){
    	if( is_array( $retarr ) && !empty( $retarr ) ){
    		//Add your fields here
    		$replaceArr = array( 'price', 'new-price', 'new price', 'LowestNewPrice' );
    		//strs to find & replace
    		$findStr 	= 'USD';
    		$replStr 	= '';
    		foreach( $retarr as $prodkey => $prodval ){
    			if( is_array( $prodval ) && !empty( $prodval ) ){
    				foreach( $prodval as $field => $value ){
    					if( in_array( $field, $replaceArr ) )
    						$retarr[ $prodkey ][ $field ] = preg_replace("/^(.*?)\s(?:".$findStr."\s?)$/i", "$1".$replStr, $value);
    				}
    			}else{
    				if( in_array( $prodkey, $replaceArr ) )
    					$retarr[ $prodkey ] = preg_replace("/^(.*?)\s(?:".$findStr."\s?)$/i", "$1".$replStr, $prodval);
    			}
    		}
    	}
    	return $retarr;
    }
    add_filter('amazon_product_in_a_post_plugin_elements_filter','amazon_product_in_a_post_plugin_elements_filter_jkhufs');

    Let me know if you have issues.
    Warmest regards,
    Don

    Forgot to mention, this will not change the one for AMAZONPRODUCTS as that does not use fields, so just the amazon-elements script was modified.

    Don

    Thanks Don. Works like a charm.

    Andrew

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

The topic ‘How to remove "USD"’ is closed to new replies.