• Resolved kieranmcclung

    (@kieranmcclung)


    I have a number of shipping zones, each with a fixed rate applied. They’re set up as follows:

    • Shipping Method #1 – Fixed Rate (30)
    • Shipping Method #2 – Fixed Rate (100)
    • Shipping Method #3 – Fixed Rate (25)
    • Shipping Method #4 – Fixed Rate (75)

    The site has two currencies set up at the moment, EUR (default) and GBP, and I need to somehow make it so that Shipping Method’s #1 and #2 are always a fixed GBP cost, i.e. £30 and £100 and that Shipping Method’s #3 and #4 are always fixed EUR, i.e. €20 and €75.

    The Euro prices are working as intended as Euro is the current default currency, however, the GBP prices are being converted so what should be £30 is actually £25.21 (at current exchange rate) because the site thinks it’s a Euro value.

    Is there any way to hook into the conversion function for shipping and add a conditional so that Shipping Method #1 and #2 base price is GBP rather than the default EUR? I’m happy to code this up myself but any pointers would be greatly appreciated.

    Thank you.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hello

    Plugin does not have this function.

    To realize this feature needs a serious development.

    So read this – https://docs.woocommerce.com/wc-apidocs/class-WC_Shipping.html + https://stackoverflow.com/questions/21147375/woocommerce-override-shipping-cost

    WOOCS uses woocommerce hook, you have to catch the price for delivery and change (after a run for my plugin)

    Thread Starter kieranmcclung

    (@kieranmcclung)

    Thanks for getting back in touch and for including some links and information. It’s given me a good starting point.

    • This reply was modified 8 years, 3 months ago by kieranmcclung. Reason: Fixed wording
    Thread Starter kieranmcclung

    (@kieranmcclung)

    I’ve attached my code below in case anyone stumbles across this and wants an answer. It’s quite basic but should hopefully help you on your way.

    
    function wpf_shipping_cost_override( $rates, $package ) {
    
    	global $WOOCS;
    	// Array of shipping rate ids
    	$gbp_rates = array( 1, 2, 3, 4 );
    	
    	foreach ( $rates as $rate ) {
    		
    		// Get rate id
    		$id = end( explode( ':', $rate->id ) );
    		
    		// Check if in gbp rate array
    		if ( in_array( $id, $gbp_rates ) ) {
    			
    			$currencies = $WOOCS->get_currencies();
    			
    			// Get current gbp rate
    			$gbp_rate = $currencies['GBP']['rate'];
    			
    			// Get cost (currently converted)
    			$cost = $rate->cost;
    			
    			// Back convert cost based on $gbp_rate
    			$new_cost = $WOOCS->back_convert( $cost, $gbp_rate );
    			
    			// Set new cost
    			$rate->cost = $new_cost;
    			
    		}
    		
    	}
    	
    	return $rates;
    	
    }
    // Priority 10000 ensure this runs after conversion
    add_filter( 'woocommerce_package_rates', 'wpf_shipping_cost_override', 10000, 2 );
    
    Plugin Author RealMag777

    (@realmag777)

    Hello

    Thank you! I will review your code for extending of the plugin functionality …

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Possible to change default currency per shipping method?’ is closed to new replies.