Forum Replies Created
- AuthorPosts
- May 13, 2020 at 4:23 am in reply to: Modifying shipping costs among multi-vendors Then to the customer location #130249abbasi.ayeParticipant
Thanks a lot of the help
In order to achieve the above target, we have two snippets,
1. Snippet-1 to add a drop-down menu in the checkout page to obtain the customer’s special sub-region.
2. Snippet-2 to fetch the selected value from the previously added drop-down menu (say store it in $user_selected_field), then use it and also using the stores in the cart to modify the shipping rate.Can you help me finding a way to get the selected value of selected value from drop down from the checkout page class?
=====================================================
2. Snippet-2 Looks like:define( ‘WP_DEBUG’, true );
add_filter( ‘woocommerce_shipping_method_add_rate_args’, ‘AA_shipping_extra_per_product’, 100, 2 );
function AA_shipping_extra_per_product( $args, $shipping_method ) {
/* Interacting with dropdown menue code
*/
$arr_co_fields = wc()->checkout()->get_checkout_fields();//($fieldset = ‘shipping’);
$user_selected_field = $arr_co_fields[‘billing’][‘billing_city’];//$_POST[$arr_co_fields[‘billing’][‘billing_city’]];
//$user_selected_field = $_POST[‘dropdown’]; // I’m not sure to read selected value by customer from drop-down menuprint_r($user_selected_field);
/* cart info
*/
$items = wc()->cart->get_cart();
foreach ( $items as $item => $values ) {
$product = wc_get_product( $values[‘data’]->get_id() );
$vendor_id = wcfm_get_vendor_id_by_post( $product->get_id() );
if ( $vendor_id ) {
$store_user = wcfmmp_get_store( $vendor_id );
$shop_name = $store_user->get_shop_name();
$url = $store_user->get_shop_url();
$address = $store_user->get_address();}
}// decision on extra shipping rate
$extra_ship = 0;
if ($vendor_id == 2 && $user_selected_field =2){
$shippnig_zone = 2
$extra_ship +=20;
} elseif($vendor_id == 3 && $user_selected_field =3){
$shippnig_zone = 3
$extra_ship +=40;
}
$args[‘cost’] = $extra_ship + 1;
return $args;
} - AuthorPosts