Created
February 2, 2017 11:41
-
-
Save WPprodigy/ad08c362f509adb88fc767db5ccb6275 to your computer and use it in GitHub Desktop.
Show cost per night in cart for WooCommerce Accommodation Bookings
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
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