1
1
13ffingers2020-10-16 22:25:28
WordPress
13ffingers, 2020-10-16 22:25:28

How to make a discount for self-delivery for certain groups of goods?

Hello, please help, I'm not really rummage, there was a similar question, but I did not find a direct answer there. I’ll thank you with a penny for coffee, if I can?)
// Essence
A 10% discount was made on the selected delivery method, it needs to be applied to certain categories of goods: ID=19 ID=20 and local_pickup

// Function for discount2

function prefix_add_discount_line( $cart ) {
$chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
$chosen_shipping_no_ajax = $chosen_methods[0];
if ( 0 === strpos( $chosen_shipping_no_ajax, 'local_pickup' ) ) {

$discount = $cart->subtotal * 0.10;
$cart->add_fee( __( 'Сумма скидки', 'yourtext-domain' ) , -$discount );
}
}
add_action( 'woocommerce_cart_calculate_fees', 'prefix_add_discount_line');

слетело после обновления, не помню как делал.

//что то типа этого было
function woo_discount_total(WC_Cart $cart) {

foreach($cart->get_cart() as $cart_item) {

if(has_term("19", "product_cat", $cart_item["product_id"]) && has_term("20", "product_cat", $cart_item["product_id"])) { // Если в корзине есть товар из категории с ID = 19 и ID = 20

$discount = $cart->subtotal * 0.10;

$cart->add_fee("Фиксированная скидка в 10% за выбор товара из акционных категорий ", -$discount);

break;

}

}

}

add_action("woocommerce_cart_calculate_fees" , "woo_discount_total");

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question