本文整理汇总了PHP中WC_Order_Item_Meta::new_order_item方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Order_Item_Meta::new_order_item方法的具体用法?PHP WC_Order_Item_Meta::new_order_item怎么用?PHP WC_Order_Item_Meta::new_order_item使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WC_Order_Item_Meta
的用法示例。
在下文中一共展示了WC_Order_Item_Meta::new_order_item方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: define
//.........这里部分代码省略.........
$errors = apply_filters('woocommerce_registration_errors', $reg_errors, $this->posted['account_username'], $this->posted['billing_email']);
// if there are no errors, let's create the user account
if (!$reg_errors->get_error_code()) {
$user_pass = esc_attr($this->posted['account_password']);
$user_id = wp_create_user($this->posted['account_username'], $user_pass, $this->posted['billing_email']);
if (!$user_id) {
$woocommerce->add_error('<strong>' . __('ERROR', 'woocommerce') . '</strong>: ' . __('Couldn’t register you… please contact us if you continue to have problems.', 'woocommerce'));
break;
}
// Change role
wp_update_user(array('ID' => $user_id, 'role' => 'customer'));
// Action
do_action('woocommerce_created_customer', $user_id);
// send the user a confirmation and their login details
$mailer = $woocommerce->mailer();
$mailer->customer_new_account($user_id, $user_pass);
// set the WP login cookie
$secure_cookie = is_ssl() ? true : false;
wp_set_auth_cookie($user_id, true, $secure_cookie);
} else {
$woocommerce->add_error($reg_errors->get_error_message());
break;
}
}
// Create Order (send cart variable so we can record items and reduce inventory). Only create if this is a new order, not if the payment was rejected last time.
$_tax = new WC_Tax();
$order_data = array('post_type' => 'shop_order', 'post_title' => sprintf(__('Order – %s', 'woocommerce'), strftime(_x('%b %d, %Y @ %I:%M %p', 'Order date parsed by strftime', 'woocommerce'))), 'post_status' => 'publish', 'ping_status' => 'closed', 'post_excerpt' => $this->posted['order_comments'], 'post_author' => 1, 'post_password' => uniqid('order_'));
// Cart items
$order_items = array();
foreach ($woocommerce->cart->get_cart() as $cart_item_key => $values) {
$_product = $values['data'];
// Store any item meta data - item meta class lets plugins add item meta in a standardized way
$item_meta = new WC_Order_Item_Meta();
$item_meta->new_order_item($values);
// Store variation data in meta so admin can view it
if ($values['variation'] && is_array($values['variation'])) {
foreach ($values['variation'] as $key => $value) {
$item_meta->add(esc_attr(str_replace('attribute_', '', $key)), $value);
}
}
// Store backorder status
if ($_product->backorders_require_notification() && $_product->is_on_backorder($values['quantity'])) {
$item_meta->add(__('Backordered', 'woocommerce'), $values['quantity'] - max(0, $_product->get_total_stock()));
}
$order_items[] = apply_filters('new_order_item', array('id' => $values['product_id'], 'variation_id' => $values['variation_id'], 'name' => $_product->get_title(), 'qty' => (int) $values['quantity'], 'item_meta' => $item_meta->meta, 'line_subtotal' => woocommerce_format_decimal($values['line_subtotal']), 'line_subtotal_tax' => woocommerce_format_decimal($values['line_subtotal_tax']), 'line_total' => woocommerce_format_decimal($values['line_total']), 'line_tax' => woocommerce_format_decimal($values['line_tax']), 'tax_class' => $_product->get_tax_class()), $values);
}
// Check order items for errors
do_action('woocommerce_check_new_order_items', $order_items);
if ($woocommerce->error_count() > 0) {
break;
}
// Insert or update the post data
$create_new_order = true;
if (isset($_SESSION['order_awaiting_payment']) && $_SESSION['order_awaiting_payment'] > 0) {
$order_id = (int) $_SESSION['order_awaiting_payment'];
/* Check order is unpaid by getting its status */
$terms = wp_get_object_terms($order_id, 'shop_order_status', array('fields' => 'slugs'));
$order_status = isset($terms[0]) ? $terms[0] : 'pending';
if ($order_status == 'pending') {
// Resume the unpaid order
$order_data['ID'] = $order_id;
wp_update_post($order_data);
do_action('woocommerce_resume_order', $order_id);
$create_new_order = false;
}
}