• Resolved tiany02

    (@tiany02)


    Hello,

    We currently have the duration discount add-on installed. However I am having trouble finding the calculated nett daily rate (after duration discount and user role discount has been applied). It there some way this value can be saved to the woocommerce_order_itemmeta table so it can be called for reporting?

    Thanks in advance for your consideration,
    Yolanda

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Ashanna

    (@morki)

    Hello,

    Try this:

    add_action( 'easy_booking_add_booked_item', 'store_daily_rate', 10, 3 );
    
    function store_daily_rate( $item, $start, $end ) {
        
        $price = $item->get_total();
    
        if ( $end ) {
    
            $start_time  = strtotime( $start );
            $end_time    = strtotime( $end );
    
            $duration = absint( ( $start_time - $end_time ) / 86400 );
    
            $daily_price = $price / $duration;
    
            $item->add_meta_data( '_daily_rate', wc_price( $daily_price ) );
    
        }
    
    }

    Regards,
    Natasha

    Thread Starter tiany02

    (@tiany02)

    Hi Natasha

    Thank you for the reply which pointed me down the right path. Here is the edited version I am using due to our product add-ons which have a cost adder. If there is a more elegant method of doing so I would be keen to improve.

    
    add_action( 'easy_booking_add_booked_item', 'store_daily_rate', 10, 3 );
    
    function store_daily_rate( $item, $start, $end ) {
    	
    	$product_id = $item->get_product_id();
    	$product = wc_get_product( $product_id );
    	$base_price = $product->get_price();
    	
        if ( $end ) {
    
            $start_time  = strtotime( $start );
            $end_time    = strtotime( $end );
    
            $duration = absint( ( $start_time - $end_time ) / 86400 +1 );
    		
    		if ($duration >= 30) {
    			$daily_price = $base_price * 0.9;
    		}
    		elseif  ($duration >= 7) {
    			$daily_price = $base_price * 0.95;
    		}
    		else {
    			$daily_price = $base_price;
    		}
    
            $item->add_meta_data( '_daily_rate', wc_price( $daily_price ) );
    
        }
    
    }

    Thank you!

    Plugin Author Ashanna

    (@morki)

    Seems fine, if it works as you want it’s ok ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘discounted daily rates’ is closed to new replies.