Advertisement
zumixosan

Dokan Cart Update

Jan 8th, 2020
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.68 KB | None | 0 0
  1. function dokan_discount_for_lot_quantity() {
  2.     $total_discount_amount_for_lot = 0;
  3.     $flag_for_lot_discount         = false;
  4.    
  5.     foreach ( WC()->cart->get_cart() as $cart_data ) {
  6.         $product_id                  = $cart_data['product_id'];
  7.         $row_item_quantity           = $cart_data['quantity'];
  8.         $line_total                  = $cart_data['line_total'];
  9.         $price_item                  = get_post_meta($product_id,'_price',true);
  10.         $is_lot_discount             = get_post_meta( $product_id, '_is_lot_discount', true );
  11.         $is_enable_op_discount       = dokan_get_option( 'discount_edit', 'dokan_selling' );
  12.         $is_product_discount_enabled = isset( $is_enable_op_discount['product-discount'] ) && $is_enable_op_discount['product-discount'] == 'product-discount';
  13.        
  14.         if ( $is_product_discount_enabled && $is_lot_discount == 'yes' ) {
  15.             $lot_discount_percentage = get_post_meta( $product_id, '_lot_discount_amount', true );
  16.             $lot_discount_quantity   = get_post_meta( $product_id, '_lot_discount_quantity', true );
  17.            
  18.             //edited Code
  19.             $lot_discount_percentage_two = get_post_meta( $product_id, '_lot_discount_amount_two', true );
  20.             $lot_discount_quantity_two   = get_post_meta( $product_id, '_lot_discount_quantity_two', true );
  21.            
  22.             //edited Code
  23.             $lot_discount_percentage_three = get_post_meta( $product_id, '_lot_discount_amount_three', true );
  24.             $lot_discount_quantity_three   = get_post_meta( $product_id, '_lot_discount_quantity_three', true );
  25.            
  26.             $discount_status = get_post_meta($product_id,'_discount_status',true);
  27.            
  28.             if($lot_discount_quantity > 0){
  29.                 if ( $row_item_quantity >= $lot_discount_quantity) {
  30.                    
  31.                     if($lot_discount_quantity_two > 0){
  32.                         if($row_item_quantity < $lot_discount_quantity_two){
  33.                             if($lot_discount_percentage > 0){
  34.                                 if($discount_status == 'percentage'){
  35.                                    
  36.                                     $final = $price_item - (($lot_discount_percentage/100)*$price_item);
  37.                                     $cart_data['data']->set_price($final);
  38.                                    
  39.                                 }else if($discount_status == 'fixed'){
  40.                                     $cart_data['data']->set_price($lot_discount_percentage);
  41.                                 }
  42.                             }else{
  43.                                 $cart_data['data']->set_price($price_item);
  44.                             }
  45.                            
  46.                         }else if($row_item_quantity >= $lot_discount_quantity_two){
  47.                            
  48.                             if($lot_discount_quantity_three > 0){
  49.                                
  50.                                 if($row_item_quantity < $lot_discount_quantity_three){
  51.                                     if($lot_discount_percentage_two > 0){
  52.                                         if($discount_status == 'percentage'){
  53.                                            
  54.                                             $final = $price_item - (($lot_discount_percentage_two/100)*$price_item);
  55.                                             $cart_data['data']->set_price($final);
  56.                                            
  57.                                         }else if($discount_status == 'fixed'){
  58.                                             $cart_data['data']->set_price($lot_discount_percentage_two);
  59.                                         }
  60.                                     }else{
  61.                                         $cart_data['data']->set_price($price_item);
  62.                                     }
  63.                                    
  64.                                 }else{
  65.                                     if($lot_discount_percentage_three > 0){
  66.                                         if($discount_status == 'percentage'){
  67.                                             $final = $price_item - (($lot_discount_percentage_three/100)*$price_item);
  68.                                             $cart_data['data']->set_price($final);
  69.                                            
  70.                                         }else if($discount_status == 'fixed'){
  71.                                             $cart_data['data']->set_price($lot_discount_percentage_three);
  72.                                         }
  73.                                     }else{
  74.                                         $cart_data['data']->set_price($price_item);
  75.                                     }
  76.                                    
  77.                                 }
  78.                             }else{
  79.                                 if($lot_discount_percentage_two > 0){
  80.                                     if($discount_status == 'percentage'){
  81.                                        
  82.                                         $final = $price_item - (($lot_discount_percentage_two/100)*$price_item);
  83.                                         $cart_data['data']->set_price($final);
  84.                                        
  85.                                     }else if($discount_status == 'fixed'){
  86.                                         $cart_data['data']->set_price($lot_discount_percentage_two);
  87.                                     }
  88.                                 }else{
  89.                                     $cart_data['data']->set_price($price_item);
  90.                                 }
  91.                             }
  92.                         }
  93.                     }else{
  94.                         if($lot_discount_percentage > 0){
  95.                             if($discount_status == 'percentage'){
  96.                                 $final = $price_item - (($lot_discount_percentage/100)*$price_item);
  97.                                 $cart_data['data']->set_price($final);
  98.                             }else if($discount_status == 'fixed'){
  99.                                 $cart_data['data']->set_price($lot_discount_percentage);
  100.                             }
  101.                         }else{
  102.                             $cart_data['data']->set_price($price_item);
  103.                         }
  104.                     }
  105.                 }
  106.             }
  107.             $flag_for_lot_discount= false;
  108.         }
  109.     }
  110.    
  111.     if ( $flag_for_lot_discount == false ) {
  112.         $total_discount_amount_for_lot = 0;
  113.     }
  114.    
  115.     return apply_filters( 'return_calculated_lot_discount', $total_discount_amount_for_lot );
  116. }
  117. add_action('woocommerce_before_calculate_totals','dokan_discount_for_lot_quantity');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement