我需要显示我的送货方式。我应该用哪个钩子做这个?
的functions.php:
add_filter('which_hook_should_i_use', 'my_shipping_function');
function my_shipping_function() {
//what code do I need to write?
}
答案 0 :(得分:0)
我是这样做的:
function ed_package_rates( $rates, $package ) {
foreach ( $rates as $rate ) {
$first_product_id = array_values( WC()->cart->get_cart() );
$product_id = $first_product_id[0]['product_id'];
$rate_label = mb_strtolower(str_replace(' ', '_', $rate->label));
$rate->cost = get_post_meta($product_id,'_my_shipping_method_'. $rate_label, true) ; // to form meta_key
}
return $rates ;
}
add_filter('woocommerce_package_rates', 'my_package_rates', 10, 2);