Skip to content

Instantly share code, notes, and snippets.

@WPprodigy
Created February 2, 2017 11:41
Show Gist options
  • Save WPprodigy/ad08c362f509adb88fc767db5ccb6275 to your computer and use it in GitHub Desktop.
Save WPprodigy/ad08c362f509adb88fc767db5ccb6275 to your computer and use it in GitHub Desktop.
Show cost per night in cart for WooCommerce Accommodation Bookings
add_action( 'woocommerce_get_item_data', 'wc_ninja_add_custom_product_meta', 15, 2 );
function wc_ninja_add_custom_product_meta( $other_data, $cart_item ) {
if ( ! empty( $cart_item['booking'] ) ) {
$item = $cart_item['booking'];
if ( 'night' === $item['_duration_unit'] ) {
$per_night = $item['_cost'] / $item['duration'];
$other_data[] = array(
'name' => 'Cost Per Night',
'value' => wc_price( $per_night ),
'display' => '',
);
}
}
return $other_data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment