Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashokrane/68ef605c2f10690dbaaaf0d32080a564 to your computer and use it in GitHub Desktop.
Save ashokrane/68ef605c2f10690dbaaaf0d32080a564 to your computer and use it in GitHub Desktop.
Seasonal Addon Price on Cart & Checkout page
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