开发者 |
hitstacks
aarsiv |
---|---|
更新时间 | 2024年10月30日 01:37 |
PHP版本: | 5.6 及以上 |
WordPress版本: | 6.7 |
版权: | GPLv3 or later License |
"Make Your Shop With Smile"Useful filters:
function ups_shipping_cost_conversion($ship_cost, $pack_weight = 0, $to_country = "", $rate_code = ""){
$sample_flat_rates = array("GB"=>array( //Use ISO 3166-1 alpha-2 as country code
"weight_from" => 10,
"weight_upto" => 30,
"rate" => 2000,
"rate_code" => "ups_12", //You can add UPS service type and use it based on your's need. Get this from our plugin's configuration (services tab).
),
"US"=>array(
"weight_from" => 1,
"weight_upto" => 30,
"rate" => 5000,
),
);
if(!empty($to_country) && !empty($sample_flat_rates)){
if(isset($sample_flat_rates[$to_country]) && ($pack_weight >= $sample_flat_rates[$to_country]['weight_from']) && ($pack_weight <= $sample_flat_rates[$to_country]['weight_upto'])){
$flat_rate = $sample_flat_rates[$to_country]['rate'];
return $flat_rate;
}else{
return $ship_cost;
}
}else{
return $ship_cost;
}
}
add_filter('hitstacks_ups_shipping_cost_conversion','ups_shipping_cost_conversion',10,4);
(Note: Flat rate filter example code will set flat rate for all UPS carriers. Have to add code to check and alter rate for specific carrier. While copy paste the code from worpress plugin page may throw error "Undefined constant". It can be fixed by replacing backtick (`) to apostrophe (') )
add_filter( 'woocommerce_package_rates' , 'hitshipo_sort_shipping_methods', 10, 2 ); function hitshipo_sort_shipping_methods( $rates, $package ) { if ( empty( $rates ) ) return; if ( ! is_array( $rates ) ) return; uasort( $rates, function ( $a, $b ) { if ( $a == $b ) return 0; return ( $a->cost < $b->cost ) ? -1 : 1; } ); return $rates; }
Wordpress version tested4.3.2
Bug Fixed