• Resolved klamottn.de

    (@klamottnde)


    Hey there, I use your Search Addon and I want to ask if there is a way to add the following functions to the search with a snippet:

    function change_existing_currency_symbol( $currency_symbol, $currency) {
         
    	$product_cats = wp_get_post_terms( get_the_ID(), 'product_cat' );
    
        if ( $product_cats && ! is_wp_error ( $product_cats ) ){
    
        $single_cat = array_shift( $product_cats ); 
    
    	$cat = $single_cat;
    	}
    	
    	switch($single_cat->name) {
              case 'Amazon US': $currency_symbol = '$ '; break;
    		  case 'Amazon GB': $currency_symbol = '£ '; break;
    		  case 'Amazon DE': $currency_symbol = '€ '; break;
    		  case 'Amazon IT': $currency_symbol = '€ '; break;
    		  case 'Amazon FR': $currency_symbol = '€ '; break;
    		  case 'Amazon ES': $currency_symbol = '€ '; break;
    	   	  case 'Amazon JP': $currency_symbol = '¥ '; break;
         }
         return $currency_symbol;
    }
    function woo_custom_format_position($format, $currency_pos)
        {
          /*'left':$format = '%1$s%2$s';
           'right':$format = '%2$s%1$s';
           'left_space':$format = '%1$s %2$s';
           'right_space':$format = '%2$s %1$s';
          */
    		
    		$product_cats = wp_get_post_terms( get_the_ID(), 'product_cat' );
    
        if ( $product_cats && ! is_wp_error ( $product_cats ) ){
    
        $single_cat = array_shift( $product_cats ); 
    
    	$cat = $single_cat;
    	}
    	
    	switch($single_cat->name) {
              case 'Amazon US': $format = '%1$s%2$s'; break;
    		  case 'Amazon GB': $format = '%1$s%2$s'; break;
    		  case 'Amazon DE': $format = '%2$s %1$s'; break;
    		  case 'Amazon IT': $format = '%2$s %1$s'; break;
    		  case 'Amazon FR': $format = '%2$s %1$s'; break;
    		  case 'Amazon ES': $format = '%2$s %1$s'; break;
    	   	  case 'Amazon JP': $format = '%1$s %2$s'; break;
         }
    		
            return $format;
            
    	}

    I use these function to format the prices in my woocommerce shop. And therefore it would be awesome to have these changes with a snippet like

    add_filter('woocommerce_currency_symbol', 'change_existing_currency_symbol', 10, 2);

    this at the search too. Also it would be very nice to know if there is a way to show the category of the search result under the result name in small. Any help would be great. Thank you!

    • This topic was modified 2 years, 1 month ago by klamottn.de.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Hi @klamottnde

    Prices in autocomplete results should be found. Details Panel may show them wrong. Use this code snippet to solve the problem:

    You have two ways to add this code to your theme:

    1. Open the functions.php in your child theme and add the code at the end.
    2. or install the?Code Snippets?plugin and apply this code as a snippet.
    // Change currency symbol in Details Panel based on product term
    add_filter( 'dgwt/wcas/suggestion_details/product/html', function( $html, $productID ) {
    
    	$currency_symbol   = '';
    	$currency_position = '';
    
    	$symbols = array(
    		'amazon-gb' => array( 's' => '£', 'p' => 'left' ),
    		'amazon-de' => array( 's' => '€', 'p' => 'right-with-space' ),
    		'amazon-it' => array( 's' => '€', 'p' => 'right-with-space' ),
    		'amazon-fr' => array( 's' => '€', 'p' => 'right-with-space' ),
    		'amazon-es' => array( 's' => '€', 'p' => 'right-with-space' ),
    		'amazon-jp' => array( 's' => '¥', 'p' => 'right-with-space' )
    	);
    
    	foreach ( $symbols as $key => $symbol ) {
    		if ( has_term( $key, 'product_cat', $productID ) ) {
    			$currency_symbol   = $symbol['s'];
    			$currency_position = $symbol['p'];
    		}
    	}
    
    	if ( $currency_symbol && $currency_position ) {
    		$html = str_replace( 'dgwt-wcas-pd-price', 'dgwt-wcas-pd-price currency-' . $currency_position, $html );
    		$html = preg_replace('/<span class="woocommerce-Price-currencySymbol">(.*?)<\/span>/', '<span class="woocommerce-Price-currencySymbol">' . $currency_symbol . '</span>', $html );
    
    		$html .= '<style>.currency-left bdi { display: inline-flex; flex-direction: row-reverse; }</style>';
    	}
    
    	return $html;
    
    }, 10, 3 );

    Regards,
    Kris

Viewing 1 replies (of 1 total)
  • The topic ‘Change Currency’ is closed to new replies.