从Woocommerce Bookings中的购物车项目中获取人员类型名称



我已经启用了Wooccommerce Bookings插件,我应该需要在结账页面上显示添加到购物车中的人员类型。

我可以通过以下代码计算人数:

foreach(WC()->cart->get_cart() as $cart_item) { 
$person = array_sum( $cart_item['booking']['_persons'] );
}

但是我需要显示人物类型名称

我怎样才能得到这些人名?


如果我在for循环中添加您的代码,它只需要一个人的类型名称。例如,我有4种类型的人,如成年人、青少年、儿童和婴儿。它只写婴儿。

for ( $i = 0; $i < $person; $i++) {
$counter = $i + 1;
$html .= " . $person_name . "; // Here
$html .= woocommerce_form_field( "participant_details[$i][full_name]", array(
"type" => "text",
"return" => true,
"value" => "",
"class"         => array('form-row-first'),
"required"      => false,
"placeholder"       => __('Name')
)
);
}

要从Wooccommerce Bookings获得可预订产品的购物车项目中的人名,请使用以下代码:

foreach(WC()->cart->get_cart() as $cart_item) {
// The item persons count
$person = array_sum( $cart_item['booking']['_persons'] );
// Get the instance of the WC_Product_Booking product
$booking = new WC_Product_Booking( $cart_item['product_id'] );
// Loop through persons array to get the person names
foreach ( $cart_item['booking']['_persons'] as $person_id => $person_qty ) {
$person_name = $booking->get_person_types()[$person_id]->get_name();
}
}

测试并工作。

最新更新