Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function dokan_get_lot_discount_for_vendor( $vendor_id ) {
- $is_enable_op_discount = dokan_get_option( 'discount_edit', 'dokan_selling' );
- $is_product_discount_enabled = isset( $is_enable_op_discount['product-discount'] ) && $is_enable_op_discount['product-discount'] == 'product-discount';
- $discount_total = 0;
- if ( ! $is_product_discount_enabled ) {
- return $discount_total;
- }
- foreach ( WC()->cart->get_cart() as $item ) {
- $product_id = $item['data']->get_id();
- $product = wc_get_product( $product_id );
- $product_discount = $product->get_meta( '_is_lot_discount', true );
- $price_item = $product->get_meta('_price',true);
- if ( $product_discount !== 'yes' ) {
- continue;
- }
- $vendor = dokan_get_vendor_by_product( $product_id );
- if ( $vendor_id !== $vendor->get_id() ) {
- continue;
- }
- $line_total = $item['line_total'];
- $item_quantity = $item['quantity'];
- $lot_discount_percentage = (float) $product->get_meta( '_lot_discount_amount', true );
- $lot_discount_quantity = absint( $product->get_meta( '_lot_discount_quantity', true ) );
- //edited code
- $lot_discount_percentage_two = (float) $product->get_meta( '_lot_discount_amount_two', true );
- $lot_discount_quantity_two = absint( $product->get_meta( '_lot_discount_quantity_two', true ) );
- $lot_discount_percentage_three = (float) $product->get_meta( '_lot_discount_amount_three', true );
- $lot_discount_quantity_three = absint( $product->get_meta( '_lot_discount_quantity_three', true ) );
- $discount_status = get_post_meta($product_id,'_discount_status',true);
- if($lot_discount_quantity != '0'){
- if ( $row_item_quantity >= $lot_discount_quantity) {
- if($lot_discount_quantity_two != '0'){
- if($row_item_quantity < $lot_discount_quantity_two){
- if($discount_status == 'percentage'){
- $discount_total += ( $line_total * $lot_discount_percentage / 100 );
- }
- }else if($row_item_quantity >= $lot_discount_quantity_two){
- if($lot_discount_quantity_three != '0'){
- if($row_item_quantity < $lot_discount_quantity_three){
- if($discount_status == 'percentage'){
- if($discount_status_two == 'percentage'){
- $discount_total += ( $line_total * $lot_discount_percentage_two / 100 );
- }
- }
- }else{
- if($discount_status_three == 'percentage'){
- $discount_total += ( $line_total * $lot_discount_percentage_three / 100 );
- }
- }
- }else{
- if($discount_status_two == 'percentage'){
- $discount_total += ( $line_total * $lot_discount_percentage_two / 100 );
- }
- }
- }
- }else{
- if($discount_status == 'percentage'){
- $discount_total += ( $line_total * $lot_discount_percentage / 100 );
- }
- }
- }
- }
- // if ( $item_quantity >= $lot_discount_quantity && $item_quantity < $lot_discount_quantity_two && $item_quantity < $lot_discount_quantity_three) {
- // if($discount_status == 'percentage'){
- // $discount_total += ( $line_total * $lot_discount_percentage / 100 );
- // }
- // }else if($item_quantity > $lot_discount_quantity_two && $item_quantity >= $lot_discount_quantity_two && $item_quantity < $lot_discount_quantity_three ){
- // if($discount_status_two == 'percentage'){
- // $discount_total += ( $line_total * $lot_discount_percentage_two / 100 );
- // }
- // }else if($item_quantity >= $lot_discount_quantity_three && $item_quantity > $lot_discount_quantity_two && $item_quantity > $lot_discount_quantity){
- // if($discount_status_three == 'percentage'){
- // $discount_total += ( $line_total * $lot_discount_percentage_three / 100 );
- // }
- // }
- }
- return $discount_total;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement