-
Üyelik
23.01.2016
-
Yaş/Cinsiyet
45 / E
-
Meslek
bilgisayar mühendisi
-
Konum
İstanbul Avrupa
-
Ad Soyad
M** E**
-
Mesajlar
1366
-
Beğeniler
9 / 379
-
Ticaret
0, (%0)
Aşağıdaki kodu kullanabilirsiniz .
add_action('woocommerce_cart_calculate_fees', 'ts_add_custom_discount', 10, 1 );
function ts_add_custom_discount( $wc_cart ){
$discount = 0;
$product_ids = array();
$in_cart = false;
foreach ( $wc_cart->get_cart() as $cart_item_key => $cart_item ) {
$cart_product = $cart_item['data'];
if ( has_term( 'get2', 'product_cat', $cart_product->get_id() ) ) {
$in_cart = true;
}else {
$product_ids[] = $cart_product->get_id();
}
}
if( $in_cart ) {
$count_ids = count($product_ids);
$count = 0;
if( $count_ids >= 1 ) {
foreach( $product_ids as $id ) {
if( $count >= 2 ) {
break;
}
$product = wc_get_product( $id );
$price = $product->get_price();
$discount -= ($price * 100) /100;
$count++;
}
}
}
if( $discount != 0 ){
$wc_cart->add_fee( 'Discount', $discount, true );
}
}