Answer the question
In order to leave comments, you need to log in
How to make paid shipping for a specific shipping method?
Hello. Help, please, with the decision of such problem.
You need to add the product (delivery cost) to the basket if courier delivery is selected and the basket amount is less than 15 rubles. If the basket is more than 15r. or another delivery is selected, then delete this product.
Shipping is exactly like a product. Adding a price through plugins to the payment method itself, as in the picture below, alas, does not work :s I
am attaching my code, what I tried to do
add_action( 'woocommerce_cart_calculate_fees','hml_delivery_price', 10, 1 );
function hml_delivery_price( WC_Cart $cart_object ) {
global $post, $woocommerce;
$delivery_name = "";
$delivery_selected = [];
$available_methods = $woocommerce->shipping->get_packages();
if(isset($woocommerce->session)) {
$delivery_selected = $woocommerce->session->get("chosen_shipping_methods");
}
foreach($available_methods as $method) {
foreach($delivery_selected as $delivery) {
if(isset($method["rates"][$delivery])) {
$delivery_name = $method["rates"][$delivery]->label;
break;
}
}
}
if($delivery_name == "Доставка курьером") {
$price_cart = WC()->cart->get_cart_subtotal();
if($price_cart >= 15.0){
$woocommerce->cart->add_to_cart(4399);
}
else{
$woocommerce->cart->remove_cart_item(4399);
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question