本文整理汇总了PHP中get_wc_booking函数的典型用法代码示例。如果您正苦于以下问题:PHP get_wc_booking函数的具体用法?PHP get_wc_booking怎么用?PHP get_wc_booking使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_wc_booking函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: trigger
/**
* trigger function.
*/
function trigger($booking_id)
{
if ($booking_id) {
$this->object = get_wc_booking($booking_id);
if ($this->object->has_status('in-cart')) {
return;
}
$this->find[] = '{product_title}';
$this->replace[] = $this->object->get_product()->get_title();
if ($this->object->get_order()) {
$this->find[] = '{order_date}';
$this->replace[] = date_i18n(wc_date_format(), strtotime($this->object->get_order()->order_date));
$this->find[] = '{order_number}';
$this->replace[] = $this->object->get_order()->get_order_number();
} else {
$this->find[] = '{order_date}';
$this->replace[] = date_i18n(wc_date_format(), strtotime($this->object->booking_date));
$this->find[] = '{order_number}';
$this->replace[] = __('N/A', 'woocommerce-bookings');
}
if (!$this->is_enabled() || !$this->get_recipient()) {
return;
}
$this->send($this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments());
}
}
示例2: cancel_booking
/**
* Cancel a booking.
*/
public static function cancel_booking()
{
if (isset($_GET['cancel_booking']) && isset($_GET['booking_id'])) {
$booking_id = absint($_GET['booking_id']);
$booking = get_wc_booking($booking_id);
$booking_can_cancel = $booking->has_status(apply_filters('woocommerce_valid_booking_statuses_for_cancel', array('unpaid', 'pending-confirmation', 'confirmed', 'paid')));
$redirect = $_GET['redirect'];
if ($booking->has_status('cancelled')) {
// Already cancelled - take no action
} elseif ($booking_can_cancel && $booking->id == $booking_id && isset($_GET['_wpnonce']) && wp_verify_nonce($_GET['_wpnonce'], 'woocommerce-bookings-cancel_booking')) {
// Cancel the booking
$booking->update_status('cancelled');
WC_Cache_Helper::get_transient_version('bookings', true);
// Message
wc_add_notice(apply_filters('woocommerce_booking_cancelled_notice', __('Your booking was cancelled.', 'woocommerce-bookings')), apply_filters('woocommerce_booking_cancelled_notice_type', 'notice'));
do_action('woocommerce_bookings_cancelled_booking', $booking->id);
} elseif (!$booking_can_cancel) {
wc_add_notice(__('Your booking can no longer be cancelled. Please contact us if you need assistance.', 'woocommerce-bookings'), 'error');
} else {
wc_add_notice(__('Invalid booking.', 'woocommerce-bookings'), 'error');
}
if ($redirect) {
wp_safe_redirect($redirect);
exit;
}
}
}
示例3: trigger
/**
* trigger function.
*
* @access public
* @return void
*/
function trigger($booking_id)
{
if ($booking_id) {
$this->object = get_wc_booking($booking_id);
if ($this->object->get_product()) {
$this->find[] = '{product_title}';
$this->replace[] = $this->object->get_product()->get_title();
}
if ($this->object->get_order()) {
$this->find[] = '{order_date}';
$this->replace[] = date_i18n(wc_date_format(), strtotime($this->object->get_order()->order_date));
$this->find[] = '{order_number}';
$this->replace[] = $this->object->get_order()->get_order_number();
$this->recipient = $this->object->get_order()->billing_email;
} else {
$this->find[] = '{order_date}';
$this->replace[] = date_i18n(wc_date_format(), strtotime($this->object->booking_date));
$this->find[] = '{order_number}';
$this->replace[] = __('N/A', 'woocommerce-bookings');
if ($this->object->customer_id && ($customer = get_user_by('id', $this->object->customer_id))) {
$this->recipient = $customer->user_email;
}
}
}
if (!$this->is_enabled() || !$this->get_recipient()) {
return;
}
$this->send($this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments());
}
示例4: trigger
/**
* trigger function.
*
* @access public
* @return void
*/
function trigger($booking_id, $notification_subject, $notification_message, $attachments = array())
{
global $woocommerce;
if ($booking_id) {
$this->object = get_wc_booking($booking_id);
$this->recipient = $this->object->get_order()->billing_email;
$this->find[] = '{product_title}';
$this->replace[] = $this->object->get_product()->get_title();
$this->find[] = '{order_date}';
$this->replace[] = date_i18n(woocommerce_date_format(), strtotime($this->object->get_order()->order_date));
$this->find[] = '{order_number}';
$this->replace[] = $this->object->get_order()->get_order_number();
$this->find[] = '{customer_name}';
$this->replace[] = $this->object->get_order()->billing_first_name . ' ' . $this->object->get_order()->billing_last_name;
$this->find[] = '{customer_first_name}';
$this->replace[] = $this->object->get_order()->billing_first_name;
$this->find[] = '{customer_last_name}';
$this->replace[] = $this->object->get_order()->billing_last_name;
}
if (!$this->is_enabled() || !$this->get_recipient()) {
return;
}
$this->heading = str_replace($this->find, $this->replace, $notification_subject);
$this->subject = str_replace($this->find, $this->replace, $notification_subject);
$this->notification_message = str_replace($this->find, $this->replace, $notification_message);
$attachments = apply_filters('woocommerce_email_attachments', $attachments, $this->id, $this->object);
$this->send($this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $attachments);
}
示例5: create_wc_booking
/**
* Validate and create a new booking manually.
*
* @see WC_Booking::new_booking() for available $new_booking_data args
* @param int $product_id you are booking
* @param array $new_booking_data
* @param string $status
* @param boolean $exact If false, the function will look for the next available block after your start date if the date is unavailable.
* @return mixed WC_Booking object on success or false on fail
*/
function create_wc_booking($product_id, $new_booking_data = array(), $status = 'confirmed', $exact = false)
{
// Merge booking data
$defaults = array('product_id' => $product_id, 'start_date' => '', 'end_date' => '', 'resource_id' => '');
$new_booking_data = wp_parse_args($new_booking_data, $defaults);
$product = get_product($product_id);
$start_date = $new_booking_data['start_date'];
$end_date = $new_booking_data['end_date'];
$max_date = $product->get_max_date();
// If not set, use next available
if (!$start_date) {
$min_date = $product->get_min_date();
$start_date = strtotime("+{$min_date['value']} {$min_date['unit']}", current_time('timestamp'));
}
// If not set, use next available + block duration
if (!$end_date) {
$end_date = strtotime("+{$product->wc_booking_duration} {$product->wc_booking_duration_unit}", $start_date);
}
$searching = true;
$date_diff = $end_date - $start_date;
while ($searching) {
$available_bookings = $this->product->get_available_bookings($start_date, $end_date, $new_booking_data['resource_id'], $data['_qty']);
if ($available_bookings && !is_wp_error($available_bookings)) {
if (!$new_booking_data['resource_id'] && is_array($available_bookings)) {
$new_booking_data['resource_id'] = current(array_keys($available_bookings));
}
$searching = false;
} else {
if ($exact) {
return false;
}
$start_date += $date_diff;
$end_date += $date_diff;
if ($end_date > strtotime("+{$max_date['value']} {$max_date['unit']}")) {
return false;
}
}
}
// Set dates
$new_booking_data['start_date'] = $start_date;
$new_booking_data['end_date'] = $end_date;
// Create it
$new_booking = get_wc_booking($new_booking_data);
$new_booking->create($status);
return $new_booking;
}
示例6: mark_booking_confirmed
/**
* Mark a booking confirmed
*/
public function mark_booking_confirmed()
{
if (!current_user_can('manage_bookings')) {
wp_die(__('You do not have sufficient permissions to access this page.', 'woocommerce-bookings'));
}
if (!check_admin_referer('wc-booking-confirm')) {
wp_die(__('You have taken too long. Please go back and retry.', 'woocommerce-bookings'));
}
$booking_id = isset($_GET['booking_id']) && (int) $_GET['booking_id'] ? (int) $_GET['booking_id'] : '';
if (!$booking_id) {
die;
}
$booking = get_wc_booking($booking_id);
if ($booking->get_status() !== 'confirmed') {
$booking->update_status('confirmed');
}
wp_safe_redirect(wp_get_referer());
}
示例7: trigger
/**
* trigger function.
*
* @access public
* @return void
*/
function trigger($booking_id)
{
global $woocommerce;
if ($booking_id) {
$this->object = get_wc_booking($booking_id);
$this->recipient = $this->object->get_order()->billing_email;
$this->find[] = '{product_title}';
$this->replace[] = $this->object->get_product()->get_title();
$this->find[] = '{order_date}';
$this->replace[] = date_i18n(woocommerce_date_format(), strtotime($this->object->get_order()->order_date));
$this->find[] = '{order_number}';
$this->replace[] = $this->object->get_order()->get_order_number();
}
if (!$this->is_enabled() || !$this->get_recipient()) {
return;
}
$this->send($this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments());
}
示例8: get_bookings_for_user
/**
* Gets bookings for a user by ID
*
* @param int $user_id The id of the user that we want bookings for
* @return array of WC_Booking objects
*/
public static function get_bookings_for_user($user_id)
{
$booking_statuses = apply_filters('woocommerce_bookings_for_user_statuses', array('unpaid', 'pending-confirmation', 'confirmed', 'paid', 'cancelled', 'complete'));
$booking_ids = get_posts(array('numberposts' => -1, 'offset' => 0, 'orderby' => 'post_date', 'order' => 'DESC', 'post_type' => 'wc_booking', 'post_status' => $booking_statuses, 'fields' => 'ids', 'no_found_rows' => true, 'meta_query' => array(array('key' => '_booking_customer_id', 'value' => absint($user_id), 'compare' => 'IN'))));
$bookings = array();
foreach ($booking_ids as $booking_id) {
$bookings[] = get_wc_booking($booking_id);
}
return $bookings;
}
示例9: order_item_meta
/**
* order_item_meta function.
*
* @param mixed $item_id
* @param mixed $values
*/
public function order_item_meta($item_id, $values)
{
global $wpdb;
if (!empty($values['booking'])) {
$product = $values['data'];
$booking_id = $values['booking']['_booking_id'];
$booking = get_wc_booking($booking_id);
$booking_status = 'unpaid';
$order_id = $wpdb->get_var($wpdb->prepare("SELECT order_id FROM {$wpdb->prefix}woocommerce_order_items WHERE order_item_id = %d", $item_id));
// Set as pending when the booking requires confirmation
if (wc_booking_requires_confirmation($values['product_id'])) {
$booking_status = 'pending-confirmation';
}
if (!$booking) {
$booking = $this->create_booking_from_cart_data($cart_item_meta, $product->id);
}
$booking->set_order_id($order_id, $item_id);
// Add summary of details to line item
foreach ($values['booking'] as $key => $value) {
if (strpos($key, '_') !== 0) {
wc_add_order_item_meta($item_id, get_wc_booking_data_label($key, $product), $value);
}
}
wc_add_order_item_meta($item_id, __('Booking ID', 'woocommerce-bookings'), $values['booking']['_booking_id']);
// Update status
$booking->update_status($booking_status);
}
}
示例10: output
/**
* Output the form
*/
public function output()
{
$this->errors = array();
$step = 1;
try {
if (!empty($_POST) && !check_admin_referer('create_booking_notification')) {
throw new Exception(__('Error - please try again', 'woocommerce-bookings'));
}
if (!empty($_POST['create_booking'])) {
$customer_id = absint($_POST['customer_id']);
$bookable_product_id = absint($_POST['bookable_product_id']);
$booking_order = wc_clean($_POST['booking_order']);
if (!$bookable_product_id) {
throw new Exception(__('Please choose a bookable product', 'woocommerce-bookings'));
}
if ($booking_order === 'existing') {
$order_id = absint($_POST['booking_order_id']);
$booking_order = $order_id;
if (!$booking_order || get_post_type($booking_order) !== 'shop_order') {
throw new Exception(__('Invalid order ID provided', 'woocommerce-bookings'));
}
}
$step++;
$product = get_product($bookable_product_id);
$booking_form = new WC_Booking_Form($product);
} elseif (!empty($_POST['create_booking_2'])) {
$customer_id = absint($_POST['customer_id']);
$bookable_product_id = absint($_POST['bookable_product_id']);
$booking_order = wc_clean($_POST['booking_order']);
$product = get_product($bookable_product_id);
$booking_form = new WC_Booking_Form($product);
$booking_data = $booking_form->get_posted_data($_POST);
$booking_cost = ($cost = $booking_form->calculate_booking_cost($_POST)) && !is_wp_error($cost) ? number_format($cost, 2, '.', '') : 0;
$create_order = false;
if ('yes' === get_option('woocommerce_prices_include_tax')) {
if (version_compare(WOOCOMMERCE_VERSION, '2.3', '<')) {
$base_tax_rates = WC_Tax::get_shop_base_rate($product->tax_class);
} else {
$base_tax_rates = WC_Tax::get_base_tax_rates($product->tax_class);
}
$base_taxes = WC_Tax::calc_tax($booking_cost, $base_tax_rates, true);
$booking_cost = round($booking_cost - array_sum($base_taxes), absint(get_option('woocommerce_price_num_decimals')));
}
// Data to go into the booking
$new_booking_data = array('user_id' => $customer_id, 'product_id' => $product->id, 'resource_id' => isset($booking_data['_resource_id']) ? $booking_data['_resource_id'] : '', 'persons' => $booking_data['_persons'], 'cost' => $booking_cost, 'start_date' => $booking_data['_start_date'], 'end_date' => $booking_data['_end_date'], 'all_day' => $booking_data['_all_day'] ? 1 : 0);
// Create order
if ($booking_order === 'new') {
$create_order = true;
$order_id = $this->create_order($booking_cost, $customer_id);
if (!$order_id) {
throw new Exception(__('Error: Could not create order', 'woocommerce-bookings'));
}
} elseif ($booking_order > 0) {
$order_id = absint($booking_order);
if (!$order_id || get_post_type($order_id) !== 'shop_order') {
throw new Exception(__('Invalid order ID provided', 'woocommerce-bookings'));
}
$order = new WC_Order($order_id);
update_post_meta($order_id, '_order_total', $order->get_total() + $booking_cost);
update_post_meta($order_id, '_booking_order', '1');
} else {
$order_id = 0;
}
if ($order_id) {
$item_id = woocommerce_add_order_item($order_id, array('order_item_name' => $product->get_title(), 'order_item_type' => 'line_item'));
if (!$item_id) {
throw new Exception(__('Error: Could not create item', 'woocommerce-bookings'));
}
// Add line item meta
woocommerce_add_order_item_meta($item_id, '_qty', 1);
woocommerce_add_order_item_meta($item_id, '_tax_class', $product->get_tax_class());
woocommerce_add_order_item_meta($item_id, '_product_id', $product->id);
woocommerce_add_order_item_meta($item_id, '_variation_id', '');
woocommerce_add_order_item_meta($item_id, '_line_subtotal', $booking_cost);
woocommerce_add_order_item_meta($item_id, '_line_total', $booking_cost);
woocommerce_add_order_item_meta($item_id, '_line_tax', 0);
woocommerce_add_order_item_meta($item_id, '_line_subtotal_tax', 0);
// We have an item id
$new_booking_data['order_item_id'] = $item_id;
// Add line item data
foreach ($booking_data as $key => $value) {
if (strpos($key, '_') !== 0) {
woocommerce_add_order_item_meta($item_id, get_wc_booking_data_label($key, $product), $value);
}
}
}
// Create the booking itself
$new_booking = get_wc_booking($new_booking_data);
$new_booking->create($create_order ? 'unpaid' : 'pending-confirmation');
wp_safe_redirect(admin_url('post.php?post=' . ($create_order ? $order_id : $new_booking->id) . '&action=edit'));
exit;
}
} catch (Exception $e) {
$this->errors[] = $e->getMessage();
}
switch ($step) {
case 1:
//.........这里部分代码省略.........
示例11: remove_booking
/**
* Remove/cancel the booking in Google Calendar
*
* @param int $booking_id Booking ID
*
* @return void
*/
public function remove_booking($booking_id)
{
$event_id = get_post_meta($booking_id, '_wc_bookings_gcalendar_event_id', true);
if ($event_id) {
$booking = get_wc_booking($booking_id);
$api_url = $this->calendars_uri . $this->calendar_id . '/events/' . $event_id;
$access_token = $this->get_access_token();
$params = array('method' => 'DELETE', 'sslverify' => false, 'timeout' => 60, 'headers' => array('Authorization' => 'Bearer ' . $access_token));
if ('yes' == $this->debug) {
$this->log->add($this->id, 'Removing booking #' . $booking->id . ' with Google Calendar...');
}
$response = wp_remote_post($api_url, $params);
if (!is_wp_error($response) && 204 == $response['response']['code']) {
if ('yes' == $this->debug) {
$this->log->add($this->id, 'Booking removed successfully!');
}
// Remove event ID
delete_post_meta($booking->id, '_wc_bookings_gcalendar_event_id');
} else {
if ('yes' == $this->debug) {
$this->log->add($this->id, 'Error while removing the booking #' . $booking->id . ': ' . print_r($response, true));
}
}
}
}
示例12: create_email_order
/**
* Send emails that matches the provided triggers to the queue
* @param int $booking_id
* @param array $triggers
*/
private function create_email_order($booking_id, $triggers = array())
{
/**
* @var $booking WC_Booking
* @var $order WC_Order
*/
$booking = get_wc_booking($booking_id);
$last_status = get_post_meta($booking_id, '_last_status', true);
$order = WC_FUE_Compatibility::wc_get_order($booking->order_id);
$emails = fue_get_emails('wc_bookings', FUE_Email::STATUS_ACTIVE, array('meta_query' => array(array('key' => '_interval_type', 'value' => $triggers, 'compare' => 'IN'))));
foreach ($emails as $email) {
if (!empty($email->meta['bookings_last_status']) && $email->meta['bookings_last_status'] != $last_status) {
continue;
}
if ($this->is_category_excluded($booking, $email)) {
continue;
}
// A booking can have no order linked to it
if ($order) {
$customer = fue_get_customer_from_order($order);
if (Follow_Up_Emails::instance()->fue_wc->wc_scheduler->exclude_customer_based_on_purchase_history($customer, $email)) {
continue;
}
}
if ($email->interval_type == 'before_booking_event') {
$start = strtotime(get_post_meta($booking_id, '_booking_start', true));
$time = FUE_Sending_Scheduler::get_time_to_add($email->interval_num, $email->interval_duration);
$send_on = $start - $time;
} elseif ($email->interval_type == 'after_booking_event') {
$start = strtotime(get_post_meta($booking_id, '_booking_end', true));
$time = FUE_Sending_Scheduler::get_time_to_add($email->interval_num, $email->interval_duration);
$send_on = $start + $time;
} else {
$send_on = $email->get_send_timestamp();
}
$insert = array('send_on' => $send_on, 'email_id' => $email->id, 'product_id' => $booking->product_id, 'order_id' => $booking->order_id, 'meta' => array('booking_id' => $booking_id));
if ($order) {
$user_id = WC_FUE_Compatibility::get_order_user_id($order);
if ($user_id) {
$user = new WP_User($user_id);
$insert['user_id'] = $user_id;
$insert['user_email'] = $user->user_email;
}
}
// Remove the nonce to avoid infinite loop because doing a
// remove_action on WC_Bookings_Details_Meta_Box doesnt work
unset($_POST['wc_bookings_details_meta_box_nonce']);
if (!is_wp_error(FUE_Sending_Scheduler::queue_email($insert, $email))) {
// Tell FUE that an email order has been created
// to stop it from sending storewide emails
if (!defined('FUE_ORDER_CREATED')) {
define('FUE_ORDER_CREATED', true);
}
}
}
}
示例13: remove_inactive_booking_from_cart
/**
* Remove inactive booking
*/
public function remove_inactive_booking_from_cart($booking_id)
{
if ($booking_id && ($booking = get_wc_booking($booking_id)) && $booking->has_status('in-cart')) {
wp_delete_post($booking_id);
}
}
示例14: output
/**
* Output the form
*/
public function output()
{
global $woocommerce;
$this->errors = array();
$step = 1;
try {
if (!empty($_POST) && !check_admin_referer('create_booking_notification')) {
throw new Exception(__('Error - please try again', 'woocommerce-bookings'));
}
if (!empty($_POST['create_booking'])) {
$customer_id = absint($_POST['customer_id']);
$bookable_product_id = absint($_POST['bookable_product_id']);
$create_order = isset($_POST['create_order']) ? 1 : 0;
if (!$bookable_product_id) {
throw new Exception(__('Please choose a bookable product', 'woocommerce-bookings'));
}
$step++;
$product = get_product($bookable_product_id);
$booking_form = new WC_Booking_Form($product);
} elseif (!empty($_POST['create_booking_2'])) {
$customer_id = absint($_POST['customer_id']);
$bookable_product_id = absint($_POST['bookable_product_id']);
$create_order = absint($_POST['create_order']);
$product = get_product($bookable_product_id);
$booking_form = new WC_Booking_Form($product);
$booking_data = $booking_form->get_posted_data($_POST);
$booking_cost = number_format($booking_form->calculate_booking_cost($_POST), 2, '.', '');
// Data to go into the booking
$new_booking_data = array('product_id' => $product->id, 'resource_id' => isset($booking_data['_resource_id']) ? $booking_data['_resource_id'] : '', 'persons' => $booking_data['_persons'], 'cost' => $booking_cost, 'start_date' => $booking_data['_start_date'], 'end_date' => $booking_data['_end_date'], 'all_day' => $booking_data['_all_day'] ? 1 : 0);
// Create order
if ($create_order) {
$order_id = $this->create_order($booking_cost, $customer_id);
if (!$order_id) {
throw new Exception(__('Error: Could not create order', 'woocommerce-bookings'));
}
$item_id = woocommerce_add_order_item($order_id, array('order_item_name' => $product->get_title(), 'order_item_type' => 'line_item'));
if (!$item_id) {
throw new Exception(__('Error: Could not create item', 'woocommerce-bookings'));
}
// Add line item meta
woocommerce_add_order_item_meta($item_id, '_qty', 1);
woocommerce_add_order_item_meta($item_id, '_tax_class', $product->get_tax_class());
woocommerce_add_order_item_meta($item_id, '_product_id', $product->id);
woocommerce_add_order_item_meta($item_id, '_variation_id', '');
woocommerce_add_order_item_meta($item_id, '_line_subtotal', $booking_cost);
woocommerce_add_order_item_meta($item_id, '_line_total', $booking_cost);
woocommerce_add_order_item_meta($item_id, '_line_tax', 0);
woocommerce_add_order_item_meta($item_id, '_line_subtotal_tax', 0);
// We have an item id
$new_booking_data['order_item_id'] = $item_id;
// Add line item data
foreach ($booking_data as $key => $value) {
if (strpos($key, '_') !== 0) {
woocommerce_add_order_item_meta($item_id, get_wc_booking_data_label($key, $product), $value);
}
}
}
// Create the booking itself
$new_booking = get_wc_booking($new_booking_data);
$new_booking->create($create_order ? 'unpaid' : 'pending');
wp_safe_redirect(admin_url('post.php?post=' . ($create_order ? $order_id : $new_booking->id) . '&action=edit'));
exit;
}
} catch (Exception $e) {
$this->errors[] = $e->getMessage();
}
switch ($step) {
case 1:
include 'views/html-create-booking-page.php';
break;
case 2:
include 'views/html-create-booking-page-2.php';
break;
}
}
示例15: remove_cancelled_booking
/**
* Removes the booking from an order
* when the order includes only bookings which require confirmation
*
* @param int $booking_id
*/
public function remove_cancelled_booking($booking_id)
{
global $wpdb;
$booking = get_wc_booking($booking_id);
$order = $booking->get_order();
$bookings = array();
foreach ($order->get_items() as $order_item_id => $item) {
if ($item[__('Booking ID', 'woocommerce-bookings')] == $booking_id) {
wc_delete_order_item($order_item_id);
$order->calculate_totals();
$order->add_order_note(sprintf(__('The product %s has been removed from the order because the booking #%d cannot be confirmed.', 'woocommerce-bookings'), $item['name'], $booking_id), true);
}
}
}