php [WooCommerce预订]使用案例:创建一周的后续行动

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php [WooCommerce预订]使用案例:创建一周的后续行动相关的知识,希望对你有一定的参考价值。


/** 
 * Code goes in theme functions.php
 *
 * In this example we're creating a booking 1 week after a booking is paid for.
 * This does not create another order or payment, just an additional booking.
 * $exact is false meaning if our slot is taken, the next available slot will be used.
 * @link https://docs.woocommerce.com/document/creating-bookings-programatically/
 */
function auto_create_followup_booking( $booking_id ) {
	
	// Get the previous booking from the ID
	$prev_booking = get_wc_booking( $booking_id );
	
	// Don't want follow ups for follow ups
	if ( $prev_booking->get_parent_id() <= 0 ) {
		// Set the follow up data
		$new_booking_data = array(
			'start_date'  => strtotime( '+1 week', $prev_booking->get_start() ), // same time, 1 week on
			'end_date'    => strtotime( '+1 week', $prev_booking->get_end() ),   // same time, 1 week on
			'resource_id' => $prev_booking->get_resource_id(),                   // same resource
			'parent_id'   => $booking_id,                                        // set the parent
		);
		// Did the previous booking have persons?
		$persons = $prev_booking->get_persons();
		if ( is_array( $persons ) && 0 < count( $persons ) ) {
			$new_booking_data['persons'] = $persons;
		}
		// Was the previous booking all day?
		if ( $prev_booking->is_all_day() ) {
			$new_booking_data['all_day'] = true;
		}
		create_wc_booking( 
			$prev_booking->get_product_id(), // Creating a booking for the previous bookings product
			$new_booking_data,               // Use the data pulled above
			$prev_booking->get_status(),     // Match previous bookings status
			false                            // Not exact, look for a slot
		);
	}
}
add_action( 'woocommerce_booking_in-cart_to_paid', 'auto_create_followup_booking' );
add_action( 'woocommerce_booking_unpaid_to_paid', 'auto_create_followup_booking' );
add_action( 'woocommerce_booking_confirmed_to_paid', 'auto_create_followup_booking' );

以上是关于php [WooCommerce预订]使用案例:创建一周的后续行动的主要内容,如果未能解决你的问题,请参考以下文章

php [WooCommerce预订]自动确认通过COD购买的预订

php [WooCommerce预订]在购物车预订到期时修改

php [WooCommerce预订]将日历默认为第一次预订

php [WooCommerce预订]在前端未使用日历选择器时更改日期格式

php [WooCommerce预订] - 产品依赖

php WooCommerce预订 - 更改购物车到期日