Created
January 19, 2022 13:05
-
-
Save ashokrane/68ef605c2f10690dbaaaf0d32080a564 to your computer and use it in GitHub Desktop.
Seasonal Addon Price on Cart & Checkout page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function bkap_woocommerce_cart_item_subtotal( $product_subtotal, $cart_item, $cart_item_key ) { | |
if ( isset( $cart_item['bkap_booking'] ) ) { | |
$booking = $cart_item['bkap_booking'][0]; | |
if ( isset( $booking[ 'hidden_date_checkout' ] ) ) { | |
$checkin_date_str = strtotime( $booking[ 'hidden_date' ] ); | |
$checkout_date_str = strtotime( $booking[ 'hidden_date_checkout' ] ); | |
$checkin_date = date( 'Y-m-d', $checkin_date_str ); | |
$checkout_date = date( 'Y-m-d', $checkout_date_str ); | |
$number_of_days = $checkout_date_str - $checkin_date_str; | |
$no_of_nights = floor( $number_of_days / 86400 ); | |
$per_day_price = $booking[ 'price' ] / $no_of_nights; | |
$product_subtotal = wc_price( $per_day_price ) . ' x ' . $no_of_nights . ' nights = ' . $product_subtotal; | |
} | |
} | |
return $product_subtotal; | |
} | |
add_filter( 'woocommerce_cart_item_subtotal', 'bkap_woocommerce_cart_item_subtotal', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment