Created
October 24, 2019 10:34
-
-
Save PluginHive/c5fd5cc2ce3799c68e1445bab23861d9 to your computer and use it in GitHub Desktop.
Display total participant as quantity in cart page (If Consider each participant as separate booking is enabled)
This file contains 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 total_participant_in_woocommerce_cart_item_quantity($product_quantity, $cart_item_key, $cart_item) { | |
$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key ); | |
$product_id = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key ); | |
if($_product->is_sold_individually()) | |
{ | |
$product_type = $_product->get_type(); | |
if( $product_type == 'phive_booking' ) | |
{ | |
$_persons_as_booking = get_post_meta( $product_id, "_phive_booking_persons_as_booking", 1 ); | |
if($_persons_as_booking=='yes' && array_key_exists('phive_booked_persons', $cart_item) && !empty($cart_item['phive_booked_persons'])) | |
{ | |
$no_of_persons=array_sum($cart_item['phive_booked_persons']); | |
$product_quantity = sprintf( '%s <input type="hidden" name="cart[%s][qty]" value="1" />',$no_of_persons, $cart_item_key ); | |
} | |
} | |
} | |
return $product_quantity; | |
} | |
add_filter( 'woocommerce_cart_item_quantity', 'total_participant_in_woocommerce_cart_item_quantity',10,3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment