Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function dokan_discount_for_lot_quantity() {
- $total_discount_amount_for_lot = 0;
- $flag_for_lot_discount = false;
- foreach ( WC()->cart->get_cart() as $cart_data ) {
- $product_id = $cart_data['product_id'];
- $row_item_quantity = $cart_data['quantity'];
- $line_total = $cart_data['line_total'];
- $price_item = get_post_meta($product_id,'_price',true);
- $is_lot_discount = get_post_meta( $product_id, '_is_lot_discount', true );
- $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';
- if ( $is_product_discount_enabled && $is_lot_discount == 'yes' ) {
- $lot_discount_percentage = get_post_meta( $product_id, '_lot_discount_amount', true );
- $lot_discount_quantity = get_post_meta( $product_id, '_lot_discount_quantity', true );
- //edited Code
- $lot_discount_percentage_two = get_post_meta( $product_id, '_lot_discount_amount_two', true );
- $lot_discount_quantity_two = get_post_meta( $product_id, '_lot_discount_quantity_two', true );
- //edited Code
- $lot_discount_percentage_three = get_post_meta( $product_id, '_lot_discount_amount_three', true );
- $lot_discount_quantity_three = get_post_meta( $product_id, '_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($lot_discount_percentage > 0){
- if($discount_status == 'percentage'){
- $final = $price_item - (($lot_discount_percentage/100)*$price_item);
- $cart_data['data']->set_price($final);
- }else if($discount_status == 'fixed'){
- $cart_data['data']->set_price($lot_discount_percentage);
- }
- }else{
- $cart_data['data']->set_price($price_item);
- }
- }else if($row_item_quantity >= $lot_discount_quantity_two){
- if($lot_discount_quantity_three > 0){
- if($row_item_quantity < $lot_discount_quantity_three){
- if($lot_discount_percentage_two > 0){
- if($discount_status == 'percentage'){
- $final = $price_item - (($lot_discount_percentage_two/100)*$price_item);
- $cart_data['data']->set_price($final);
- }else if($discount_status == 'fixed'){
- $cart_data['data']->set_price($lot_discount_percentage_two);
- }
- }else{
- $cart_data['data']->set_price($price_item);
- }
- }else{
- if($lot_discount_percentage_three > 0){
- if($discount_status == 'percentage'){
- $final = $price_item - (($lot_discount_percentage_three/100)*$price_item);
- $cart_data['data']->set_price($final);
- }else if($discount_status == 'fixed'){
- $cart_data['data']->set_price($lot_discount_percentage_three);
- }
- }else{
- $cart_data['data']->set_price($price_item);
- }
- }
- }else{
- if($lot_discount_percentage_two > 0){
- if($discount_status == 'percentage'){
- $final = $price_item - (($lot_discount_percentage_two/100)*$price_item);
- $cart_data['data']->set_price($final);
- }else if($discount_status == 'fixed'){
- $cart_data['data']->set_price($lot_discount_percentage_two);
- }
- }else{
- $cart_data['data']->set_price($price_item);
- }
- }
- }
- }else{
- if($lot_discount_percentage > 0){
- if($discount_status == 'percentage'){
- $final = $price_item - (($lot_discount_percentage/100)*$price_item);
- $cart_data['data']->set_price($final);
- }else if($discount_status == 'fixed'){
- $cart_data['data']->set_price($lot_discount_percentage);
- }
- }else{
- $cart_data['data']->set_price($price_item);
- }
- }
- }
- }
- $flag_for_lot_discount= false;
- }
- }
- if ( $flag_for_lot_discount == false ) {
- $total_discount_amount_for_lot = 0;
- }
- return apply_filters( 'return_calculated_lot_discount', $total_discount_amount_for_lot );
- }
- add_action('woocommerce_before_calculate_totals','dokan_discount_for_lot_quantity');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement