Advertisement
zumixosan

Dokan Cart Update 3

Jan 8th, 2020
393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.63 KB | None | 0 0
  1. /**
  2.  * Function for display lot quantity
  3.  *
  4.  */
  5. function show_lot_discount(){
  6.     global $post;
  7.     $product = wc_get_product($post->ID);
  8.     $product_id = $product->get_id();
  9.     $is_lot_discount = get_post_meta( $product_id, '_is_lot_discount', true );
  10.  
  11.     if($is_lot_discount == 'yes'){
  12.         $lot_discount_quantity   = get_post_meta( $product_id, '_lot_discount_quantity', true );
  13.         $lot_discount_percentage = get_post_meta( $product_id, '_lot_discount_amount', true );
  14.  
  15.         $lot_discount_percentage_two = get_post_meta( $product_id, '_lot_discount_amount_two', true );
  16.         $lot_discount_quantity_two   = get_post_meta( $product_id, '_lot_discount_quantity_two', true );
  17.            
  18.         $lot_discount_percentage_three = get_post_meta( $product_id, '_lot_discount_amount_three', true );
  19.         $lot_discount_quantity_three   = get_post_meta( $product_id, '_lot_discount_quantity_three', true );
  20.  
  21.         $discount_status = get_post_meta($product_id,'_discount_status',true);
  22.         $discount_status_two = get_post_meta($product_id,'_discount_status_two',true);
  23.         $discount_status_three = get_post_meta($product_id,'_discount_status_three',true);
  24.  
  25.         if($product->get_sale_price()<='0'){
  26.             $price = $product->get_price();
  27.         }else{
  28.             $price = $product->get_sale_price();
  29.         }
  30.  
  31.         ?>
  32.         <table class="dokan-table dokan-table-striped dokan-inline-editable-table" id="dokan-product-list-table">
  33.             <thead>
  34.                 <tr align="center">
  35.                     <th>Quantity</th>
  36.                     <th>Bulk Purchase Pricing</th>
  37.                 </tr>
  38.             </thead>
  39.             <tbody>
  40.                 <?php
  41.                 if($lot_discount_quantity > 0){
  42.                     if($lot_discount_percentage > 0){
  43.                 ?>
  44.                 <tr align="center">
  45.                     <td>
  46.                         <?php
  47.                            
  48.                             if($lot_discount_quantity_two > $lot_discount_quantity){
  49.                                 $isi = $lot_discount_quantity_two - 1;
  50.                                 if($isi == $lot_discount_quantity_two){
  51.                                     echo $lot_discount_quantity;
  52.                                 }else if($isi <= 1){
  53.                                     echo $lot_discount_quantity;
  54.                                 }else{
  55.                                     echo $lot_discount_quantity." - ".$isi;
  56.                                 }
  57.                             }else{
  58.                                 echo $lot_discount_quantity." or more";
  59.                             }
  60.                            
  61.                         ?>
  62.                     </td>
  63.                     <td>
  64.                         <?php
  65.  
  66.                             if($discount_status == 'percentage'){
  67.                                  $final = $price - (($lot_discount_percentage/100)*$price);
  68.                             echo get_woocommerce_currency_symbol()." ".number_format($final,2);
  69.                            
  70.                             }else if($discount_status == 'fixed'){
  71.                                 echo get_woocommerce_currency_symbol()." ".number_format($lot_discount_percentage);
  72.                             }
  73.                         ?>
  74.                     </td>
  75.                 </tr>
  76.                 <?php
  77.                 }
  78.                 if($lot_discount_quantity_two > $lot_discount_quantity){
  79.                     if($lot_discount_percentage_two > 0){
  80.                 ?>
  81.                 <tr align="center">
  82.                     <td>
  83.                         <?php
  84.                             if($lot_discount_quantity_three > $lot_discount_quantity_two){
  85.                                 //echo $lot_discount_quantity_two." - ". ($lot_discount_quantity_three - 1);
  86.                                 $isi = $lot_discount_quantity_three - 1;
  87.                                 if($isi == $lot_discount_quantity_three){
  88.                                     echo $lot_discount_quantity_two;
  89.                                 }else if($isi <= '1'){
  90.                                     echo $lot_discount_quantity_two;
  91.                                 }else{
  92.                                     echo $lot_discount_quantity_two." - ".$isi;
  93.                                     //echo "test";
  94.                                 }
  95.                             }else{
  96.                                 echo $lot_discount_quantity_two." or more";
  97.                             }
  98.                         ?>
  99.                     </td>
  100.                     <td>
  101.                         <?php
  102.                             if($discount_status == 'percentage'){
  103.                                  $final = $price - (($lot_discount_percentage_two/100)*$price);
  104.                             echo get_woocommerce_currency_symbol()." ".number_format($final,2);
  105.                             }else if($discount_status == 'fixed'){
  106.  
  107.                                 echo get_woocommerce_currency_symbol()." ".number_format($lot_discount_percentage_two);
  108.                             }
  109.                            
  110.                         ?>
  111.                     </td>
  112.                 </tr>
  113.                 <?php
  114.                     }
  115.                 }
  116.  
  117.                 if($lot_discount_quantity_three > $lot_discount_quantity_two){
  118.                     if($lot_discount_percentage_three > 0){
  119.                 ?>
  120.                 <tr align="center">
  121.                     <td>
  122.                         <?php
  123.                             echo $lot_discount_quantity_three." or more";
  124.                         ?>
  125.                     </td>
  126.                     <td>
  127.                         <?php
  128.                             if($discount_status == 'percentage'){
  129.                                 $final = $price - (($lot_discount_percentage_three/100)*$price);
  130.                                 echo get_woocommerce_currency_symbol()." ".number_format($final,2);
  131.                             }else if($discount_status == 'fixed'){
  132.                                  echo get_woocommerce_currency_symbol()." ".number_format($lot_discount_percentage_three);
  133.                             }
  134.                            
  135.                         ?>
  136.                     </td>
  137.                 </tr>
  138.                 <?php
  139.                     }
  140.                 }
  141.                 }?>
  142.             </tbody>
  143.         </table>
  144.         <?php
  145.     }
  146. }
  147. //add_action('woocommerce_cart_totals_before_order_total','show_lot_discount');
  148. add_action('woocommerce_before_add_to_cart_form','show_lot_discount');
  149. //add_action('woocommerce_product_meta_end','show_lot_discount');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement