Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Is there a way to include the SKU instead of the Product ID?

    Best regards,

    Jesse

    Hi Dan,

    Is there a custom fix possible to change the sort order of the shipping methods?
    I found this snippet on the forum and hoped it could be changed a bit to solve this issue:

    add_filter('woocommerce_package_rates', 'wf_sort_shipping_methods', 10, 2);
    
    function wf_sort_shipping_methods($available_shipping_methods, $package)
    {
    	// Arrange shipping methods as per your requirement
    	$sort_order	= array(
    		'wf_shipping_ups'	=>	array(),
    		'wf_shipping_usps'	=>	array(),
    		'free_shipping'		=>	array(),
    		'local_pickup'		=>	array(),
    		'legacy_flat_rate'	=>	array(),		
    	);
    	
    	// unsetting all methods that needs to be sorted
    	foreach($available_shipping_methods as $carrier_id => $carrier){
    		$carrier_name	=	current(explode(":",$carrier_id));
    		if(array_key_exists($carrier_name,$sort_order)){
    			$sort_order[$carrier_name][$carrier_id]	=		$available_shipping_methods[$carrier_id];
    			unset($available_shipping_methods[$carrier_id]);
    		}
    	}
    	
    	// adding methods again according to sort order array
    	foreach($sort_order as $carriers){
    		$available_shipping_methods	=	array_merge($available_shipping_methods,$carriers);
    	}
    	return $available_shipping_methods;
    }

    In my case I only need the local_pickup and the weight based shipping methods.

    But I’m not an expert in code.. so hopefully someone else is. ??

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