本文整理汇总了PHP中WC_Order::get_items方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Order::get_items方法的具体用法?PHP WC_Order::get_items怎么用?PHP WC_Order::get_items使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WC_Order
的用法示例。
在下文中一共展示了WC_Order::get_items方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: add_edit_address_subscription_action
/**
* Add a "Change Shipping Address" button to the "My Subscriptions" table for those subscriptions
* which require shipping.
*
* @param array $all_actions The $subscription_key => $actions array with all actions that will be displayed for a subscription on the "My Subscriptions" table
* @param array $subscriptions All of a given users subscriptions that will be displayed on the "My Subscriptions" table
* @since 1.3
*/
public static function add_edit_address_subscription_action($all_actions, $subscriptions)
{
foreach ($all_actions as $subscription_key => $actions) {
$order = new WC_Order($subscriptions[$subscription_key]['order_id']);
$needs_shipping = false;
foreach ($order->get_items() as $item) {
if ($item['product_id'] !== $subscriptions[$subscription_key]['product_id']) {
continue;
}
$product = $order->get_product_from_item($item);
if (!is_object($product)) {
// In case a product has been deleted
continue;
}
if ($product->needs_shipping()) {
$needs_shipping = true;
}
}
if ($needs_shipping && in_array($subscriptions[$subscription_key]['status'], array('active', 'on-hold'))) {
// WC 2.1+
if (function_exists('wc_get_endpoint_url')) {
$all_actions[$subscription_key] = array('change_address' => array('url' => add_query_arg(array('subscription' => $subscription_key), wc_get_endpoint_url('edit-address', 'shipping')), 'name' => __('Change Address', 'woocommerce-subscriptions'))) + $all_actions[$subscription_key];
} else {
$all_actions[$subscription_key] = array('change_address' => array('url' => add_query_arg(array('address' => 'shipping', 'subscription' => $subscription_key), get_permalink(woocommerce_get_page_id('edit_address'))), 'name' => __('Change Address', 'woocommerce-subscriptions'))) + $all_actions[$subscription_key];
}
}
}
return $all_actions;
}
示例2: admin_sms_alert
function admin_sms_alert($order_id)
{
global $woocommerce;
$order = new WC_Order($order_id);
$billing_firstname = get_post_meta($order_id, '_billing_first_name', true);
$billing_lastname = get_post_meta($order_id, '_billing_last_name', true);
$billing_phone = get_post_meta($order_id, '_billing_phone', true);
$shipping_address1 = get_post_meta($order_id, '_billing_address_1', true);
$shipping_address2 = get_post_meta($order_id, '_billing_address_2', true);
$medallion = strtoupper(get_user_meta($order->user_id, 'loyalty_status', true));
$order_amount = get_post_meta($order_id, '_order_total', true);
$pay_type = get_post_meta($order_id, '_payment_method', true);
if ($pay_type == 'cod') {
$pay_method = 'Cash on delivery';
} else {
$pay_method = 'Credit card on delivery';
}
$order_item = $order->get_items();
foreach ($order_item as $product) {
$product_meta[] = $product['name'] . ' (' . strtok($product['item_meta']['size'][0], ' ') . ')';
}
$product_list = implode("\n", $product_meta);
$admin_sms = "New Order #{$order_id}\n" . "{$product_list}\n" . "{$medallion}\n" . "Total \${$order_amount}\n" . "{$pay_method}\n" . "{$billing_firstname} {$billing_lastname}\n" . "{$shipping_address1}" . ($shipping_address2 ? " {$shipping_address2}" : '') . "\n" . "{$billing_phone}";
require 'twilio-php/Services/Twilio.php';
$account_sid = 'AC48732db704fe33f0601c8b61bd1519b8';
$auth_token = 'b881c619f25d20143bbbf6ac4d0d3429';
$admin_phone = array('+13109253443', '+18185102424', '+18183392676');
foreach ($admin_phone as $number) {
$client = new Services_Twilio($account_sid, $auth_token);
$client->account->messages->create(array('To' => $number, 'From' => "+13232104996", 'Body' => $admin_sms));
}
}
示例3: is_available
public function is_available()
{
$order = null;
if (!WC()->cart->needs_shipping()) {
return false;
}
if (is_page(wc_get_page_id('checkout')) && 0 < get_query_var('order-pay')) {
$order_id = absint(get_query_var('order-pay'));
$order = new WC_Order($order_id);
// Test if order needs shipping.
$needs_shipping = false;
if (0 < sizeof($order->get_items())) {
foreach ($order->get_items() as $item) {
$_product = $order->get_product_from_item($item);
if ($_product->needs_shipping()) {
$needs_shipping = true;
break;
}
}
}
$needs_shipping = apply_filters('woocommerce_cart_needs_shipping', $needs_shipping);
if ($needs_shipping) {
return false;
}
}
if (!empty($this->enable_for_methods)) {
// Only apply if all packages are being shipped via local pickup
$chosen_shipping_methods_session = WC()->session->get('chosen_shipping_methods');
if (isset($chosen_shipping_methods_session)) {
$chosen_shipping_methods = array_unique($chosen_shipping_methods_session);
} else {
$chosen_shipping_methods = array();
}
$check_method = false;
if (is_object($order)) {
if ($order->shipping_method) {
$check_method = $order->shipping_method;
}
} elseif (empty($chosen_shipping_methods) || sizeof($chosen_shipping_methods) > 1) {
$check_method = false;
} elseif (sizeof($chosen_shipping_methods) == 1) {
$check_method = $chosen_shipping_methods[0];
}
if (!$check_method) {
return false;
}
$found = false;
foreach ($this->enable_for_methods as $method_id) {
if (strpos($check_method, $method_id) === 0) {
$found = true;
break;
}
}
if (!$found) {
return false;
}
}
return parent::is_available();
}
示例4: callKiteApi
public function callKiteApi($order_status, $order_id)
{
$order = new WC_Order($order_id);
if (count($order->get_items()) > 0) {
foreach ($order->get_items() as $item) {
if ($item['id'] > 0) {
$_product = $order->get_product_from_item($item);
$quantity = $item['qty'];
mail('kmrsfrnc@gmail.com', 'New Order', $item['id'] . ' x ' . $quantity);
}
}
}
}
示例5: wpuw_custom_woocommerce_auto_complete_order
function wpuw_custom_woocommerce_auto_complete_order($order_id)
{
if (!$order_id) {
return;
}
$order = new WC_Order($order_id);
if (count($order->get_items()) > 0) {
foreach ($order->get_items() as $item) {
if (has_term('credit', 'product_cat', $item['product_id'])) {
$order->update_status('completed');
}
}
}
}
示例6: order_paid
/**
* Triggered when an order is paid
* @param int $order_id
*/
public function order_paid($order_id)
{
// Get the order
$order = new WC_Order($order_id);
if (get_post_meta($order_id, 'wc_paid_listings_packages_processed', true)) {
return;
}
foreach ($order->get_items() as $item) {
$product = wc_get_product($item['product_id']);
if ($product->is_type(array('job_package', 'resume_package', 'job_package_subscription', 'resume_package_subscription')) && $order->customer_user) {
// Give packages to user
for ($i = 0; $i < $item['qty']; $i++) {
$user_package_id = wc_paid_listings_give_user_package($order->customer_user, $product->id, $order_id);
}
// Approve job or resume with new package
if (isset($item['job_id'])) {
$job = get_post($item['job_id']);
if (in_array($job->post_status, array('pending_payment', 'expired'))) {
wc_paid_listings_approve_job_listing_with_package($job->ID, $order->customer_user, $user_package_id);
}
} elseif (isset($item['resume_id'])) {
$resume = get_post($item['resume_id']);
if (in_array($resume->post_status, array('pending_payment', 'expired'))) {
wc_paid_listings_approve_resume_with_package($resume->ID, $order->customer_user, $user_package_id);
}
}
}
}
update_post_meta($order_id, 'wc_paid_listings_packages_processed', true);
}
示例7: get_product_name
/**
* @since 1.0
* @return string Product Name
*/
private function get_product_name($order_id)
{
$order = new WC_Order($order_id);
$items = $order->get_items();
// Get the first ordered item
$item = array_shift($items);
return $item['name'];
}
开发者ID:KevinFairbanks,项目名称:woocommerce-software-activations,代码行数:12,代码来源:class-wc-software-activations.php
示例8: order_completed
/**
* Generate codes
*/
public function order_completed($order_id)
{
global $wpdb;
if (get_post_meta($order_id, 'has_api_product_licence_keys', true)) {
return;
// Only do this once
}
$order = new WC_Order($order_id);
$has_key = false;
if (sizeof($order->get_items()) > 0) {
foreach ($order->get_items() as $item) {
$product = $order->get_product_from_item($item);
if ('yes' === get_post_meta($product->id, '_is_api_product_licence', true)) {
if (!$product->variation_id || !($activation_limit = get_post_meta($product->variation_id, '_licence_activation_limit', true))) {
$activation_limit = get_post_meta($product->id, '_licence_activation_limit', true);
}
if (!$product->variation_id || !($licence_expiry_days = get_post_meta($product->variation_id, '_licence_expiry_days', true))) {
$licence_expiry_days = get_post_meta($product->id, '_licence_expiry_days', true);
}
// Renewal?
$_renewing_key = false;
foreach ($item['item_meta'] as $meta_key => $meta_value) {
if ($meta_key == '_renewing_key') {
$_renewing_key = $meta_value[0];
}
}
if ($_renewing_key) {
// Update old key
$wpdb->update("{$wpdb->prefix}wp_plugin_licencing_licences", array('order_id' => $order_id, 'activation_limit' => $activation_limit, 'activation_email' => $order->billing_email, 'user_id' => $order->customer_user, 'date_expires' => !empty($licence_expiry_days) ? date("Y-m-d H:i:s", strtotime("+{$licence_expiry_days} days", current_time('timestamp'))) : ''), array('licence_key' => $_renewing_key));
} else {
// Generate new keys
for ($i = 0; $i < absint($item['qty']); $i++) {
// Generate a licence key
$data = array('order_id' => $order_id, 'activation_email' => $order->billing_email, 'user_id' => $order->customer_user, 'product_id' => $product->variation_id ? $product->variation_id : $product->id, 'activation_limit' => $activation_limit, 'date_expires' => !empty($licence_expiry_days) ? date("Y-m-d H:i:s", strtotime("+{$licence_expiry_days} days", current_time('timestamp'))) : '');
$licence_id = $this->save_licence_key($data);
}
}
$has_key = true;
}
}
}
if ($has_key) {
update_post_meta($order_id, 'has_api_product_licence_keys', 1);
}
}
示例9: order_status_changed
public static function order_status_changed($id, $status = '', $new_status = '')
{
$rules = get_option('woorule_rules', array());
foreach ($rules as $k => $rule) {
$enabled = get_option($rule['enabled']['id']) === 'yes' ? true : false;
if ($enabled) {
$which_event = get_option($rule['occurs']['id']);
$is_opt_in_rule = false;
$want_in = true;
if (isset($rule['show_opt_in'])) {
$is_opt_in_rule = get_option($rule['show_opt_in']['id']) === 'yes' ? true : false;
}
if ($is_opt_in_rule) {
$want_in = get_post_meta($id, 'woorule_opt_in_' . $k, false);
if (!empty($want_in)) {
$want_in = $want_in[0] === 'yes' ? true : false;
}
}
if ($want_in && $new_status === $which_event) {
$integration = new WC_Integration_RuleMailer();
$order = new WC_Order($id);
$user = $order->get_user();
$currency = $order->get_order_currency();
$order_subtotal = $order->order_total - ($order->order_shipping_tax + $order->order_shipping) - $order->cart_discount;
$items = $order->get_items();
$brands = array();
$categories = array();
$tags = array();
foreach ($items as $item) {
$p = new WC_Product_Simple($item['product_id']);
$brands[] = $p->get_attribute('brand');
// this is bullshit
$cat = strip_tags($p->get_categories(''));
$tag = strip_tags($p->get_tags(''));
if (!empty($cat)) {
$categories[] = $cat;
}
if (!empty($tag)) {
$tags[] = $tag;
}
}
$subscription = array('apikey' => $integration->api_key, 'update_on_duplicate' => get_option($rule['update_on_duplicate']['id']) === 'yes' ? true : false, 'auto_create_tags' => get_option($rule['auto_create_tags']['id']) === 'yes' ? true : false, 'auto_create_fields' => get_option($rule['auto_create_fields']['id']) === 'yes' ? true : false, 'tags' => explode(',', get_option($rule['tags']['id'])), 'subscribers' => array('email' => $order->billing_email, 'phone_number' => $order->billing_phone, 'fields' => array(array('key' => 'Order.Number', 'value' => $order->get_order_number()), array('key' => 'Order.Date', 'value' => $order->order_date), array('key' => 'Order.FirstName', 'value' => $order->billing_first_name), array('key' => 'Order.LastName', 'value' => $order->billing_last_name), array('key' => 'Order.Street1', 'value' => $order->billing_address_1), array('key' => 'Order.Street2', 'value' => $order->billing_address_2), array('key' => 'Order.City', 'value' => $order->billing_city), array('key' => 'Order.Country', 'value' => $order->billing_country), array('key' => 'Order.State', 'value' => $order->billing_state), array('key' => 'Order.Subtotal', 'value' => $order_subtotal), array('key' => 'Order.Discount', 'value' => $order->cart_discount), array('key' => 'Order.Shipping', 'value' => $order->order_shipping + $order->order_shipping_tax), array('key' => 'Order.Total', 'value' => $order->order_total), array('key' => 'Order.Vat', 'value' => $order->order_tax))));
if (!empty($categories)) {
$subscription['subscribers']['fields'][] = array('key' => 'Order.Categories', 'value' => $categories, 'type' => 'multiple');
}
if (!empty($tags)) {
$subscription['subscribers']['fields'][] = array('key' => 'Order.Tags', 'value' => array($tags), 'type' => 'multiple');
}
if (!empty($brands)) {
$subscription['subscribers']['fields'][] = array('key' => 'Order.Brands', 'value' => $brands, 'type' => 'multiple');
}
$api = WP_RuleMailer_API::get_instance();
$api::subscribe($integration->api_url, $subscription);
}
}
}
}
示例10: woocommerce_order_submit
function woocommerce_order_submit($order_id)
{
$to = 'thakurjay25@gmail.com';
$subject = 'Order recive' . $order_id;
$body = 'Order ID' . $order_id;
wp_mail($to, $subject, $body, $headers);
$IsUrgent = false;
$order = new WC_Order($order_id);
$data_submit = get_post_meta($order_id, 'data_submit', true);
//$data_submit = '';
if ($data_submit != 'Y') {
$myuser_id = (int) $order->user_id;
$user_info = get_userdata($myuser_id);
$billing_first_name = get_user_meta($myuser_id, 'billing_first_name', true);
$billing_last_name = get_user_meta($myuser_id, 'billing_last_name', true);
$items = $order->get_items();
$products = array();
foreach ($items as $item) {
$products[] = $item['product_id'];
}
$products = array_unique($products);
$del_val = 576;
if (($key = array_search($del_val, $products)) !== false) {
unset($products[$key]);
}
$products = array_values($products);
$urjent_prd = 574;
if (in_array($urjent_prd, $products)) {
$IsUrgent = true;
}
if (($key = array_search($urjent_prd, $products)) !== false) {
unset($products[$key]);
}
$products = array_values($products);
$prd_array = array('566' => 1, '570' => 2, '568' => 3, '572' => 4);
$Countries = new WC_Countries($order->billing_country);
$state = $Countries->states[$order->billing_country][$order->billing_state];
foreach ($products as $product) {
$product_id = $prd_array[$product];
$first_name = $billing_first_name;
$last_name = $billing_last_name;
$phone = $order->billing_phone;
$email = $order->billing_email;
$postcode = $order->billing_postcode;
$suburb = $order->billing_city;
$city = $state;
$address_line = $order->billing_address_1 . ', ' . $order->billing_address_2;
$dateofhairsample = date('Y-m-d');
//[current timestamp (should be this format '2015-04-05' . 'T00:00:00')]
$dateofbirth = date('Y-m-d h:i:s', time());
//[get from custom order field (should be this format '2015-04-05' . 'T00:00:00')]
include 'api/new_soap_submission.php';
}
update_post_meta($order_id, 'data_submit', 'Y');
}
}
示例11: new_comment
/**
* Submit a comment for an order
*
* @param object $orders
*
* @return unknown
*/
public static function new_comment($orders)
{
global $woocommerce;
$user = wp_get_current_user();
$user = $user->ID;
// Security
if (!wp_verify_nonce($_POST['_wpnonce'], 'add-comment')) {
return false;
}
// Check if this product belongs to the vendor submitting the comment
$product_id = (int) $_POST['product_id'];
$author = PV_Vendors::get_vendor_from_product($product_id);
if ($author != $user) {
return false;
}
// Find the order belonging to this comment
foreach ($orders as $order) {
if ($order->order_id == $_POST['order_id']) {
$found_order = $order;
break;
}
}
// No order was found
if (empty($found_order)) {
return false;
}
// Don't submit empty comments
if (empty($_POST['comment_text'])) {
if (function_exists('wc_add_error')) {
wc_add_error(__('You\'ve left the comment field empty!', 'wc_product_vendor'));
} else {
$woocommerce->add_error(__('You\'ve left the comment field empty!', 'wc_product_vendor'));
}
return false;
}
// Only submit if the order has the product belonging to this vendor
$found_order = new WC_Order($found_order->order_id);
$valid_order = false;
foreach ($found_order->get_items() as $item) {
if ($item['product_id'] == $product_id) {
$valid_order = true;
break;
}
}
if ($valid_order) {
$comment = esc_textarea($_POST['comment_text']);
add_filter('woocommerce_new_order_note_data', array(__CLASS__, 'filter_comment'), 10, 2);
$found_order->add_order_note($comment, 1);
remove_filter('woocommerce_new_order_note_data', array(__CLASS__, 'filter_comment'), 10, 2);
if (function_exists('wc_add_message')) {
wc_add_message(__('Success. The customer has been notified of your comment.', 'wc_product_vendor'));
} else {
$woocommerce->add_message(__('Success. The customer has been notified of your comment.', 'wc_product_vendor'));
}
}
}
示例12: delete_order
/**
* Delete a product.
*
* @param int $order_id ID of the order to delete.
*/
public static function delete_order($order_id)
{
$order = new WC_Order($order_id);
// Delete all products in the order
foreach ($order->get_items() as $item) {
WC_Helper_Product::delete_product($item['product_id']);
}
WC_Helper_Shipping::delete_simple_flat_rate();
// Delete the order post
wp_delete_post($order_id, true);
}
示例13: restore_order_stock
public function restore_order_stock($order_id)
{
$order = new WC_Order($order_id);
if (!get_option('woocommerce_manage_stock') == 'yes' && !sizeof($order->get_items()) > 0) {
return;
}
foreach ($order->get_items() as $item) {
if ($item['product_id'] > 0) {
$_product = $order->get_product_from_item($item);
if ($_product && $_product->exists() && $_product->managing_stock()) {
$old_stock = $_product->stock;
$qty = apply_filters('woocommerce_order_item_quantity', $item['qty'], $this, $item);
$new_quantity = $_product->increase_stock($qty);
do_action('woocommerce_auto_stock_restored', $_product, $item);
$order->add_order_note(sprintf(__('Item #%s stock incremented from %s to %s.', 'woocommerce'), $item['product_id'], $old_stock, $new_quantity));
$order->send_stock_notifications($_product, $new_quantity, $item['qty']);
}
}
}
}
开发者ID:TiagoSilvestre,项目名称:PluginParaBaixarEstoqueNoPedido,代码行数:20,代码来源:woocommerce-reduces-inventory-in-order.php
示例14: update_stock_on_checkout_nopayment
/**
*
*/
public function update_stock_on_checkout_nopayment($order_id)
{
global $woocommerce, $wpdb;
// order object (optional but handy)
$order = new WC_Order($order_id);
$items = $order->get_items();
$varation_ids = array();
var_dump($items);
//return false;
die;
}
示例15: get_bundled_order_item_container
/**
* Find the parent of a bundled item in an order.
*
* @param array $item
* @param WC_Order $order
* @return array $item
*/
public function get_bundled_order_item_container($item, $order)
{
// find container item
foreach ($order->get_items() as $order_item) {
$is_parent = isset($item['mnm_container']) && isset($order_item['mnm_cart_key']) && $item['mnm_container'] === $order_item['mnm_cart_key'];
if ($is_parent) {
$parent_item = $order_item;
return $parent_item;
}
}
return false;
}
开发者ID:helgatheviking,项目名称:wc-extension-boilerplate,代码行数:19,代码来源:class-wc-extension-boilerplate-order.php