Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • 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!

    Thread Starter tiany02

    (@tiany02)

    Yes it did thanks. Marked as resolved ??

    Thread Starter tiany02

    (@tiany02)

    Hi,

    Thanks for looking into this.

    Both messages appear on the product page at the same time, with “Sorry, this product cannnot…” on top, and “View cart …” below.
    And the item does not appear in the cart.

    Cheers
    Yolanda

    • This reply was modified 6 years, 5 months ago by tiany02.
Viewing 3 replies - 1 through 3 (of 3 total)