Advertisement
zumixosan

Dokan Cart Update 2

Jan 8th, 2020
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.97 KB | None | 0 0
  1. function dokan_get_lot_discount_for_vendor( $vendor_id ) {
  2.    
  3.     $is_enable_op_discount       = dokan_get_option( 'discount_edit', 'dokan_selling' );
  4.     $is_product_discount_enabled = isset( $is_enable_op_discount['product-discount'] ) && $is_enable_op_discount['product-discount'] == 'product-discount';
  5.     $discount_total              = 0;
  6.    
  7.     if ( ! $is_product_discount_enabled ) {
  8.         return $discount_total;
  9.     }
  10.    
  11.     foreach ( WC()->cart->get_cart() as $item ) {
  12.        
  13.         $product_id       = $item['data']->get_id();
  14.         $product          = wc_get_product( $product_id );
  15.         $product_discount = $product->get_meta( '_is_lot_discount', true );
  16.         $price_item = $product->get_meta('_price',true);
  17.         if ( $product_discount !== 'yes' ) {
  18.             continue;
  19.         }
  20.        
  21.         $vendor = dokan_get_vendor_by_product( $product_id );
  22.        
  23.         if ( $vendor_id !== $vendor->get_id() ) {
  24.             continue;
  25.         }
  26.        
  27.         $line_total              = $item['line_total'];
  28.         $item_quantity           = $item['quantity'];
  29.         $lot_discount_percentage = (float) $product->get_meta( '_lot_discount_amount', true );
  30.         $lot_discount_quantity   = absint( $product->get_meta( '_lot_discount_quantity', true ) );
  31.        
  32.         //edited code
  33.         $lot_discount_percentage_two = (float) $product->get_meta( '_lot_discount_amount_two', true );
  34.         $lot_discount_quantity_two   = absint( $product->get_meta( '_lot_discount_quantity_two', true ) );
  35.        
  36.         $lot_discount_percentage_three = (float) $product->get_meta( '_lot_discount_amount_three', true );
  37.         $lot_discount_quantity_three   = absint( $product->get_meta( '_lot_discount_quantity_three', true ) );
  38.        
  39.         $discount_status = get_post_meta($product_id,'_discount_status',true);
  40.        
  41.        
  42.         if($lot_discount_quantity != '0'){
  43.             if ( $row_item_quantity >= $lot_discount_quantity) {
  44.                
  45.                 if($lot_discount_quantity_two != '0'){
  46.                     if($row_item_quantity < $lot_discount_quantity_two){
  47.                        
  48.                         if($discount_status == 'percentage'){
  49.                             $discount_total += ( $line_total * $lot_discount_percentage / 100 );
  50.                         }
  51.                        
  52.                     }else if($row_item_quantity >= $lot_discount_quantity_two){
  53.                        
  54.                         if($lot_discount_quantity_three != '0'){
  55.                            
  56.                             if($row_item_quantity < $lot_discount_quantity_three){
  57.                                
  58.                                 if($discount_status == 'percentage'){
  59.                                     if($discount_status_two == 'percentage'){
  60.                                         $discount_total += ( $line_total * $lot_discount_percentage_two / 100 );
  61.                                     }
  62.                                 }
  63.                                
  64.                             }else{
  65.                                
  66.                                 if($discount_status_three == 'percentage'){
  67.                                     $discount_total += ( $line_total * $lot_discount_percentage_three / 100 );
  68.                                 }
  69.                                
  70.                             }
  71.                         }else{
  72.                            
  73.                             if($discount_status_two == 'percentage'){
  74.                                 $discount_total += ( $line_total * $lot_discount_percentage_two / 100 );
  75.                             }
  76.                         }
  77.                     }
  78.                 }else{
  79.                     if($discount_status == 'percentage'){
  80.                         $discount_total += ( $line_total * $lot_discount_percentage / 100 );
  81.                     }
  82.                 }
  83.             }
  84.         }
  85.        
  86.         // if ( $item_quantity >= $lot_discount_quantity && $item_quantity < $lot_discount_quantity_two && $item_quantity < $lot_discount_quantity_three) {
  87.         //     if($discount_status == 'percentage'){
  88.         //         $discount_total += ( $line_total * $lot_discount_percentage / 100 );
  89.         //     }
  90.         // }else if($item_quantity > $lot_discount_quantity_two && $item_quantity >= $lot_discount_quantity_two && $item_quantity < $lot_discount_quantity_three ){
  91.         //     if($discount_status_two == 'percentage'){
  92.         //         $discount_total += ( $line_total * $lot_discount_percentage_two / 100 );
  93.         //     }
  94.         // }else if($item_quantity >= $lot_discount_quantity_three && $item_quantity > $lot_discount_quantity_two && $item_quantity > $lot_discount_quantity){
  95.        
  96.         //     if($discount_status_three == 'percentage'){
  97.         //         $discount_total += ( $line_total * $lot_discount_percentage_three / 100 );
  98.         //     }
  99.         // }
  100.     }
  101.    
  102.     return $discount_total;
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement