本文整理汇总了PHP中woocommerce_update_order_item_meta函数的典型用法代码示例。如果您正苦于以下问题:PHP woocommerce_update_order_item_meta函数的具体用法?PHP woocommerce_update_order_item_meta怎么用?PHP woocommerce_update_order_item_meta使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了woocommerce_update_order_item_meta函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: fix_order_item_meta
/**
* We use a trial period to make sure totals are calculated correctly (i.e. order total does not include any recurring amounts)
* but we don't want switched subscriptions to actually have a trial period, so reset the value on the order after checkout.
*
* @since 1.4
*/
public static function fix_order_item_meta($item_id, $values)
{
if (false !== self::cart_contains_subscription_switch()) {
woocommerce_update_order_item_meta($item_id, '_subscription_trial_length', 0);
woocommerce_update_order_item_meta($item_id, '_subscription_trial_expiry_date', 0);
}
}
开发者ID:jgabrielfreitas,项目名称:MultipagosTestesAPP,代码行数:13,代码来源:class-wc-subscriptions-switcher.php
示例2: update_order_details
//.........这里部分代码省略.........
//print_r($meta_ids);
foreach ($meta as $mk_key => $mk_value) {
if ($mk_value['meta_key'] == get_option('book.item-meta-date') || $mk_value['meta_key'] == strip_tags(get_option("checkout.item-meta-date")) && in_array($mk_key, $meta_ids)) {
$key = $mk_value['meta_key'];
$meta_id = $mk_value['meta_id'];
//echo $key;
$booking[$key] = $mk_value['meta_value'];
$order_key_exists = 'Y';
}
}
//print_r($meta);exit;
if (count($booking) == 0) {
foreach ($meta_keys as $mk_key => $mk_value) {
foreach ($meta_values as $mv_key => $mv_value) {
if ($mk_key == $mv_key && in_array($mk_key, $meta_ids)) {
$booking[$mk_value] = $mv_value;
$order_key_exists = 'N';
}
}
}
}
$booking_settings = get_post_meta($post_id, 'woocommerce_booking_settings', true);
//echo get_option('book.item-meta-time');
//print_r($meta_keys);
//print_r($booking);
$date_name = get_option('book.item-meta-date');
global $bkap_block_booking;
$number_of_fixed_price_blocks = $bkap_block_booking->get_fixed_blocks_count($post_id);
//print_r($number_of_fixed_price_blocks);exit;
$check_out_name = strip_tags(get_option("checkout.item-meta-date"));
if (isset($booking_settings['booking_fixed_block_enable']) && $booking_settings['booking_fixed_block_enable'] == 'yes' && (isset($number_of_fixed_price_blocks) && $number_of_fixed_price_blocks > 0) && isset($booking[$check_out_name]) && $booking[$check_out_name] != "") {
if (isset($booking[$date_name]) && $booking[$date_name] != "") {
$date_select = $booking[$date_name];
woocommerce_update_order_item_meta($cart_item_key, $date_name, sanitize_text_field($date_select, true));
}
}
$date_checkout_select = '';
if (isset($booking[$check_out_name]) && $booking[$check_out_name] != "") {
//echo "here in checkout";
//print_r($booking[$check_out_name]);exit;
$date_checkout_select = $booking[$check_out_name];
woocommerce_update_order_item_meta($cart_item_key, $check_out_name, sanitize_text_field($date_checkout_select, true));
if ($order_key_exists == 'Y') {
$total_price = $line_subtotal[$cart_item_key];
$line_subtotal[$cart_item_key] = $total_price;
} else {
if (isset($_POST['wapbk_admin_hidden_date_checkout_' . $cart_item_key])) {
$checkout_date = $_POST['wapbk_admin_hidden_date_checkout_' . $cart_item_key];
}
if (isset($_POST['wapbk_admin_hidden_date_' . $cart_item_key])) {
$checkin_date = $_POST['wapbk_admin_hidden_date_' . $cart_item_key];
}
$days = (strtotime($checkout_date) - strtotime($checkin_date)) / (60 * 60 * 24);
//echo $days;
//print_r($_POST['']);exit;
if (isset($_POST['wapbk_admin_same_day_' . $cart_item_key]) && $_POST['wapbk_admin_same_day_' . $cart_item_key] == 'on') {
if ($days >= 0) {
//if(is_plugin_active('bkap-rental/rental.php') && isset($booking_settings['booking_charge_per_day']) && $booking_settings['booking_charge_per_day'] == 'on')
if (isset($_POST['add_days_' . $cart_item_key])) {
$days = $days + $_POST['add_days_' . $cart_item_key];
}
//echo $days;exit;
$total_price = $days * $line_subtotal[$cart_item_key] * $values['qty'];
}
} else {
if ($days > 0) {
开发者ID:noikiy,项目名称:Refine-woocommerce-booking,代码行数:67,代码来源:admin-bookings.php
示例3: prefill_order_item_meta
/**
* If the subscription being generated is synced, set the syncing related meta data correctly.
*
* @since 1.5
*/
public static function prefill_order_item_meta($item, $item_id)
{
$product_id = $item['variation_id'] ? $item['variation_id'] : $item['product_id'];
if (self::is_product_synced($product_id)) {
$order_id = $_POST['order_id'];
// If the date the subscription is being added is not the sync date, make sure the line total is only equal to the sign up fee (or $0 if no sign up fee)
if (!self::is_today(self::calculate_first_payment_date($product_id, 'timestamp')) && !self::is_product_prorated(get_product($product_id))) {
$line_total_keys = array('line_subtotal', 'line_total');
foreach ($line_total_keys as $line_total_key) {
$item[$line_total_key] = WC_Subscriptions_Product::get_sign_up_fee($product_id);
woocommerce_update_order_item_meta($item_id, '_' . $line_total_key, $item[$line_total_key]);
}
}
update_post_meta($order_id, '_order_contains_synced_subscription', 'true');
}
return $item;
}
开发者ID:akshayxhtmljunkies,项目名称:brownglock,代码行数:22,代码来源:class-wc-subscriptions-synchroniser.php
示例4: update_subscription
/**
* Takes a subscription key and array of subscription details and updates the users subscription details accordingly.
*
* @uses wp_parse_args To allow only part of a subscription's details to be updated, like status.
* @param string $subscription_key A subscription key of the form created by @see self::get_subscription_key()
* @param array $new_subscription_details An array of arrays with a subscription key and corresponding 'detail' => 'value' pair. Can alter any of these details:
* 'start_date' The date the subscription was activated
* 'expiry_date' The date the subscription expires or expired, false if the subscription will never expire
* 'failed_payments' The date the subscription's trial expires or expired, false if the subscription has no trial period
* 'end_date' The date the subscription ended, false if the subscription has not yet ended
* 'status' Subscription status can be: cancelled, active, expired or failed
* 'completed_payments' An array of MySQL formatted dates for all payments that have been made on the subscription
* 'failed_payments' An integer representing a count of failed payments
* 'suspension_count' An integer representing a count of the number of times the subscription has been suspended for this billing period
* @since 1.4
*/
public static function update_subscription($subscription_key, $new_subscription_details)
{
$subscription = self::get_subscription($subscription_key);
$item_id = WC_Subscriptions_Order::get_item_id_by_subscription_key($subscription_key);
$item = WC_Subscriptions_Order::get_item_by_id($item_id);
if (isset($new_subscription_details['status']) && 'deleted' == $new_subscription_details['status']) {
woocommerce_delete_order_item($item_id);
} else {
$subscription_meta = array('start_date', 'expiry_date', 'trial_expiry_date', 'end_date', 'status', 'failed_payments', 'completed_payments', 'suspension_count');
foreach ($subscription_meta as $meta_key) {
if (isset($new_subscription_details[$meta_key]) && $new_subscription_details[$meta_key] != $subscription[$meta_key]) {
$subscription[$meta_key] = $new_subscription_details[$meta_key];
woocommerce_update_order_item_meta($item_id, '_subscription_' . $meta_key, $new_subscription_details[$meta_key]);
}
}
}
do_action('updated_users_subscription', $subscription_key, $new_subscription_details);
return $subscription;
}
开发者ID:jgabrielfreitas,项目名称:MultipagosTestesAPP,代码行数:35,代码来源:class-wc-subscriptions-manager.php
示例5: woocommerce_process_shop_order_meta
//.........这里部分代码省略.........
}
// Update date
if (empty($_POST['order_date'])) {
$date = current_time('timestamp');
} else {
$date = strtotime($_POST['order_date'] . ' ' . (int) $_POST['order_date_hour'] . ':' . (int) $_POST['order_date_minute'] . ':00');
}
$date = date_i18n('Y-m-d H:i:s', $date);
$wpdb->query($wpdb->prepare("UPDATE {$wpdb->posts} SET post_date = %s, post_date_gmt = %s WHERE ID = %s", $date, get_gmt_from_date($date), $post_id));
// Tax rows
if (isset($_POST['order_taxes_id'])) {
$get_values = array('order_taxes_id', 'order_taxes_rate_id', 'order_taxes_amount', 'order_taxes_shipping_amount');
foreach ($get_values as $value) {
${$value} = isset($_POST[$value]) ? $_POST[$value] : array();
}
foreach ($order_taxes_id as $item_id) {
$item_id = absint($item_id);
$rate_id = absint($order_taxes_rate_id[$item_id]);
if ($rate_id) {
$rate = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}woocommerce_tax_rates WHERE tax_rate_id = %s", $rate_id));
$label = $rate->tax_rate_name ? $rate->tax_rate_name : $woocommerce->countries->tax_or_vat();
$compound = $rate->tax_rate_compound ? 1 : 0;
$code = array();
$code[] = $rate->tax_rate_country;
$code[] = $rate->tax_rate_state;
$code[] = $rate->tax_rate_name ? $rate->tax_rate_name : 'TAX';
$code[] = absint($rate->tax_rate_priority);
$code = strtoupper(implode('-', array_filter($code)));
} else {
$code = '';
$label = $woocommerce->countries->tax_or_vat();
}
$wpdb->update($wpdb->prefix . "woocommerce_order_items", array('order_item_name' => woocommerce_clean($code)), array('order_item_id' => $item_id), array('%s'), array('%d'));
woocommerce_update_order_item_meta($item_id, 'rate_id', $rate_id);
woocommerce_update_order_item_meta($item_id, 'label', $label);
woocommerce_update_order_item_meta($item_id, 'compound', $compound);
if (isset($order_taxes_amount[$item_id])) {
woocommerce_update_order_item_meta($item_id, 'tax_amount', woocommerce_clean($order_taxes_amount[$item_id]));
}
if (isset($order_taxes_shipping_amount[$item_id])) {
woocommerce_update_order_item_meta($item_id, 'shipping_tax_amount', woocommerce_clean($order_taxes_shipping_amount[$item_id]));
}
}
}
// Order items + fees
if (isset($_POST['order_item_id'])) {
$get_values = array('order_item_id', 'order_item_name', 'order_item_qty', 'line_subtotal', 'line_subtotal_tax', 'line_total', 'line_tax', 'order_item_tax_class');
foreach ($get_values as $value) {
${$value} = isset($_POST[$value]) ? $_POST[$value] : array();
}
foreach ($order_item_id as $item_id) {
$item_id = absint($item_id);
if (isset($order_item_name[$item_id])) {
$wpdb->update($wpdb->prefix . "woocommerce_order_items", array('order_item_name' => woocommerce_clean($order_item_name[$item_id])), array('order_item_id' => $item_id), array('%s'), array('%d'));
}
if (isset($order_item_qty[$item_id])) {
woocommerce_update_order_item_meta($item_id, '_qty', apply_filters('woocommerce_stock_amount', $order_item_qty[$item_id]));
}
if (isset($item_tax_class[$item_id])) {
woocommerce_update_order_item_meta($item_id, '_tax_class', woocommerce_clean($item_tax_class[$item_id]));
}
if (isset($line_subtotal[$item_id])) {
woocommerce_update_order_item_meta($item_id, '_line_subtotal', woocommerce_clean($line_subtotal[$item_id]));
}
if (isset($line_subtotal_tax[$item_id])) {
woocommerce_update_order_item_meta($item_id, '_line_subtotal_tax', woocommerce_clean($line_subtotal_tax[$item_id]));
开发者ID:bulats,项目名称:chef,代码行数:67,代码来源:writepanel-order_data.php
示例6: add_order_meta
/**
* When a new order is inserted, add subscriptions related order meta.
*
* @since 1.0
*/
public static function add_order_meta($order_id, $posted)
{
global $woocommerce;
if (!WC_Subscriptions_Cart::cart_contains_subscription_renewal('child') && WC_Subscriptions_Order::order_contains_subscription($order_id)) {
// This works because the 'woocommerce_add_order_item_meta' runs before the 'woocommerce_checkout_update_order_meta' hook
// Set the recurring totals so totals display correctly on order page
update_post_meta($order_id, '_order_recurring_discount_cart', WC_Subscriptions_Cart::get_recurring_discount_cart());
update_post_meta($order_id, '_order_recurring_discount_cart_tax', WC_Subscriptions_Cart::get_recurring_discount_cart_tax());
update_post_meta($order_id, '_order_recurring_discount_total', WC_Subscriptions_Cart::get_recurring_discount_total());
update_post_meta($order_id, '_order_recurring_shipping_tax_total', WC_Subscriptions_Cart::get_recurring_shipping_tax_total());
update_post_meta($order_id, '_order_recurring_shipping_total', WC_Subscriptions_Cart::get_recurring_shipping_total());
update_post_meta($order_id, '_order_recurring_tax_total', WC_Subscriptions_Cart::get_recurring_total_tax());
update_post_meta($order_id, '_order_recurring_total', WC_Subscriptions_Cart::get_recurring_total());
// Set the recurring payment method - it starts out the same as the original by may change later
update_post_meta($order_id, '_recurring_payment_method', get_post_meta($order_id, '_payment_method', true));
update_post_meta($order_id, '_recurring_payment_method_title', get_post_meta($order_id, '_payment_method_title', true));
$order = new WC_Order($order_id);
$order_fees = $order->get_fees();
// the fee order items have already been set, we just need to to add the recurring total meta
$cart_fees = $woocommerce->cart->get_fees();
foreach ($order->get_fees() as $item_id => $order_fee) {
// Find the matching fee in the cart
foreach ($cart_fees as $fee_index => $cart_fee) {
if (sanitize_title($order_fee['name']) == $cart_fee->id) {
woocommerce_add_order_item_meta($item_id, '_recurring_line_total', wc_format_decimal($cart_fee->recurring_amount));
woocommerce_add_order_item_meta($item_id, '_recurring_line_tax', wc_format_decimal($cart_fee->recurring_tax));
unset($cart_fees[$fee_index]);
break;
}
}
}
// Get recurring taxes into same format as _order_taxes
$order_recurring_taxes = array();
foreach (WC_Subscriptions_Cart::get_recurring_taxes() as $tax_key => $tax_amount) {
$item_id = woocommerce_add_order_item($order_id, array('order_item_name' => WC_Tax::get_rate_code($tax_key), 'order_item_type' => 'recurring_tax'));
if ($item_id) {
wc_add_order_item_meta($item_id, 'rate_id', $tax_key);
wc_add_order_item_meta($item_id, 'label', WC_Tax::get_rate_label($tax_key));
wc_add_order_item_meta($item_id, 'compound', absint(WC_Tax::is_compound($tax_key) ? 1 : 0));
wc_add_order_item_meta($item_id, 'tax_amount', wc_format_decimal(isset(WC()->cart->recurring_taxes[$tax_key]) ? WC()->cart->recurring_taxes[$tax_key] : 0));
wc_add_order_item_meta($item_id, 'shipping_tax_amount', wc_format_decimal(isset(WC()->cart->recurring_shipping_taxes[$tax_key]) ? WC()->cart->recurring_shipping_taxes[$tax_key] : 0));
}
}
$payment_gateways = $woocommerce->payment_gateways->payment_gateways();
if ('yes' == get_option(WC_Subscriptions_Admin::$option_prefix . '_turn_off_automatic_payments', 'no')) {
update_post_meta($order_id, '_wcs_requires_manual_renewal', 'true');
} elseif (isset($payment_gateways[$posted['payment_method']]) && !$payment_gateways[$posted['payment_method']]->supports('subscriptions')) {
update_post_meta($order_id, '_wcs_requires_manual_renewal', 'true');
}
$cart_item = WC_Subscriptions_Cart::cart_contains_subscription_renewal();
if (isset($cart_item['subscription_renewal']) && 'parent' == $cart_item['subscription_renewal']['role']) {
update_post_meta($order_id, '_original_order', $cart_item['subscription_renewal']['original_order']);
}
// WC 2.1+
if (!WC_Subscriptions::is_woocommerce_pre('2.1')) {
// Recurring coupons
if ($applied_coupons = $woocommerce->cart->get_coupons()) {
foreach ($applied_coupons as $code => $coupon) {
if (!isset($woocommerce->cart->recurring_coupon_discount_amounts[$code])) {
continue;
}
$item_id = woocommerce_add_order_item($order_id, array('order_item_name' => $code, 'order_item_type' => 'recurring_coupon'));
// Add line item meta
if ($item_id) {
woocommerce_add_order_item_meta($item_id, 'discount_amount', isset($woocommerce->cart->recurring_coupon_discount_amounts[$code]) ? $woocommerce->cart->recurring_coupon_discount_amounts[$code] : 0);
}
}
}
// Add recurring shipping order items
if (WC_Subscriptions_Cart::cart_contains_subscriptions_needing_shipping()) {
$packages = $woocommerce->shipping->get_packages();
$checkout = $woocommerce->checkout();
foreach ($packages as $i => $package) {
if (isset($package['rates'][$checkout->shipping_methods[$i]])) {
$method = $package['rates'][$checkout->shipping_methods[$i]];
$item_id = woocommerce_add_order_item($order_id, array('order_item_name' => $method->label, 'order_item_type' => 'recurring_shipping'));
if ($item_id) {
woocommerce_add_order_item_meta($item_id, 'method_id', $method->id);
woocommerce_add_order_item_meta($item_id, 'cost', WC_Subscriptions::format_total($method->cost));
woocommerce_add_order_item_meta($item_id, 'taxes', array_map('wc_format_decimal', $method->taxes));
do_action('woocommerce_subscriptions_add_recurring_shipping_order_item', $order_id, $item_id, $i);
}
}
}
}
// Remove shipping on original order if it was added but is not required
if (!WC_Subscriptions_Cart::charge_shipping_up_front()) {
foreach ($order->get_shipping_methods() as $order_item_id => $shipping_method) {
woocommerce_update_order_item_meta($order_item_id, 'cost', WC_Subscriptions::format_total(0));
}
}
} else {
update_post_meta($order_id, '_recurring_shipping_method', get_post_meta($order_id, '_shipping_method', true), true);
update_post_meta($order_id, '_recurring_shipping_method_title', get_post_meta($order_id, '_shipping_method_title', true), true);
}
//.........这里部分代码省略.........
开发者ID:akshayxhtmljunkies,项目名称:brownglock,代码行数:101,代码来源:class-wc-subscriptions-checkout.php
示例7: prefill_order_item_meta
/**
* Add subscription related order item meta when a subscription product is added as an item to an order via Ajax.
*
* @param item_id int An order_item_id as returned by the insert statement of @see woocommerce_add_order_item()
* @since 1.2.5
* @version 1.4
* @return void
*/
public static function prefill_order_item_meta($item, $item_id)
{
$order_id = $_POST['order_id'];
$product_id = $item['variation_id'] ? $item['variation_id'] : $item['product_id'];
if ($item_id && WC_Subscriptions_Product::is_subscription($product_id)) {
$order = new WC_Order($order_id);
$_product = get_product($product_id);
$recurring_amount = $_product->get_price_excluding_tax();
$sign_up_fee = $_product->get_sign_up_fee_excluding_tax();
$free_trial_length = WC_Subscriptions_Product::get_trial_length($product_id);
woocommerce_add_order_item_meta($item_id, '_subscription_period', WC_Subscriptions_Product::get_period($product_id));
woocommerce_add_order_item_meta($item_id, '_subscription_interval', WC_Subscriptions_Product::get_interval($product_id));
woocommerce_add_order_item_meta($item_id, '_subscription_length', WC_Subscriptions_Product::get_length($product_id));
woocommerce_add_order_item_meta($item_id, '_subscription_trial_length', $free_trial_length);
woocommerce_add_order_item_meta($item_id, '_subscription_trial_period', WC_Subscriptions_Product::get_trial_period($product_id));
woocommerce_add_order_item_meta($item_id, '_subscription_recurring_amount', $recurring_amount);
woocommerce_add_order_item_meta($item_id, '_subscription_sign_up_fee', $sign_up_fee);
woocommerce_add_order_item_meta($item_id, '_recurring_line_total', $recurring_amount);
woocommerce_add_order_item_meta($item_id, '_recurring_line_tax', 0);
woocommerce_add_order_item_meta($item_id, '_recurring_line_subtotal', $recurring_amount);
woocommerce_add_order_item_meta($item_id, '_recurring_line_subtotal_tax', 0);
WC_Subscriptions_Manager::create_pending_subscription_for_order($order_id, $item['product_id']);
switch ($order->status) {
case 'completed':
case 'processing':
woocommerce_update_order_item_meta($item_id, '_subscription_status', 'active');
break;
case 'on-hold':
woocommerce_update_order_item_meta($item_id, '_subscription_status', 'on-hold');
break;
case 'failed':
case 'cancelled':
woocommerce_add_order_item_meta($item_id, '_subscription_status', 'cancelled');
break;
}
// We need to override the line totals to $0 when there is a free trial
if ($free_trial_length > 0 || $sign_up_fee > 0) {
$line_total_keys = array('line_subtotal', 'line_total');
// Make sure sign up fees are included in the total (or $0 if no sign up fee and a free trial)
foreach ($line_total_keys as $line_total_key) {
$item[$line_total_key] = $sign_up_fee;
}
// If there is no free trial, make sure line totals include sign up fee and recurring fees
if (0 == $free_trial_length) {
foreach ($line_total_keys as $line_total_key) {
$item[$line_total_key] += $recurring_amount;
}
}
foreach ($line_total_keys as $line_total_key) {
$item[$line_total_key] = WC_Subscriptions::format_total($item[$line_total_key], 2);
}
} else {
$item['line_subtotal'] = $recurring_amount;
$item['line_total'] = $recurring_amount;
}
woocommerce_update_order_item_meta($item_id, '_line_subtotal', $item['line_subtotal']);
woocommerce_update_order_item_meta($item_id, '_line_total', $item['line_total']);
}
return $item;
}
开发者ID:akshayxhtmljunkies,项目名称:brownglock,代码行数:68,代码来源:class-wc-subscriptions-order.php
示例8: bp_course_disable_access
function bp_course_disable_access($order_id)
{
$order = new WC_Order($order_id);
$items = $order->get_items();
$user_id = $order->user_id;
foreach ($items as $item) {
$product_id = $item['product_id'];
$subscribed = get_post_meta($product_id, 'vibe_subscription', true);
$courses = vibe_sanitize(get_post_meta($product_id, 'vibe_courses', false));
if (isset($courses) && is_array($courses)) {
foreach ($courses as $course) {
delete_post_meta($course, $user_id);
delete_user_meta($user_id, $course);
$group_id = get_post_meta($course, 'vibe_group', true);
if (isset($group_id) && function_exists('groups_remove_member')) {
groups_remove_member($user_id, $group_id);
} else {
$group_id = '';
}
$instructors = apply_filters('wplms_course_instructors', get_post_field('post_author', $course, 'raw'), $course);
if (is_array($instructors)) {
foreach ($instructors as $instructor) {
woocommerce_update_order_item_meta($item_id, 'commission' . $instructor, 0);
//Nulls the commission
}
}
do_action('wplms_course_unsubscribe', $course_id, $user_id, $group_id);
}
}
}
}
开发者ID:nikitansk,项目名称:devschool,代码行数:31,代码来源:bp-course-actions.php
示例9: generate_renewal_order
//.........这里部分代码省略.........
$item_ids[] = woocommerce_add_order_item($renewal_order_id, array('order_item_name' => $recurring_shipping_item['name'], 'order_item_type' => 'recurring_shipping'));
}
// Add shipping item meta
foreach ($item_ids as $item_id) {
woocommerce_add_order_item_meta($item_id, 'method_id', $recurring_shipping_item['method_id']);
woocommerce_add_order_item_meta($item_id, 'cost', woocommerce_clean($failed_payment_multiplier * $recurring_shipping_item['cost']));
}
}
}
// Set line totals to be recurring line totals and remove the subscription/recurring related item meta from each order item
$order_items = WC_Subscriptions_Order::get_recurring_items($original_order);
// Allow extensions to add/remove items or item meta
$order_items = apply_filters('woocommerce_subscriptions_renewal_order_items', $order_items, $original_order->id, $renewal_order_id, $product_id, $args['new_order_role']);
if (true === $args['checkout_renewal']) {
$cart_items = $woocommerce->cart->get_cart();
}
foreach ($order_items as $item_index => $order_item) {
if ('child' == $args['new_order_role']) {
$renewal_order_item_name = sprintf(__('Renewal of "%s" purchased in Order %s', 'woocommerce-subscriptions'), $order_item['name'], $original_order->get_order_number());
} else {
$renewal_order_item_name = $order_item['name'];
}
$renewal_order_item_name = apply_filters('woocommerce_subscriptions_renewal_order_item_name', $renewal_order_item_name, $order_item, $original_order);
// Create order line item on the renewal order
$recurring_item_id = woocommerce_add_order_item($renewal_order_id, array('order_item_name' => $renewal_order_item_name, 'order_item_type' => 'line_item'));
if (true === $args['checkout_renewal']) {
$cart_item = array();
foreach ($cart_items as $item) {
if ($item['product_id'] == $order_item['product_id'] && (empty($order_item['variation_id']) || $item['variation_id'] == $order_item['variation_id'])) {
$cart_item = $item;
}
}
if (!empty($cart_item)) {
woocommerce_update_order_item_meta($recurring_item_id, '_line_total', woocommerce_format_decimal($cart_item['line_total']));
woocommerce_update_order_item_meta($recurring_item_id, '_line_tax', woocommerce_format_decimal($cart_item['line_tax']));
woocommerce_update_order_item_meta($recurring_item_id, '_line_subtotal', woocommerce_format_decimal($cart_item['line_subtotal']));
woocommerce_update_order_item_meta($recurring_item_id, '_line_subtotal_tax', woocommerce_format_decimal($cart_item['line_subtotal_tax']));
if (is_object($cart_item['data'])) {
woocommerce_update_order_item_meta($recurring_item_id, '_tax_class', $cart_item['data']->get_tax_class());
}
}
$cart_items = $woocommerce->cart->get_cart();
}
$item_meta = new WC_Order_Item_Meta($order_item['item_meta']);
// Remove recurring line items and set item totals based on recurring line totals
foreach ($item_meta->meta as $meta_key => $meta) {
// $meta is an array, so the item needs to be extracted from $meta[0] (just like order meta on a WC Order)
$meta_value = $meta[0];
if (false === $args['checkout_renewal']) {
// Already set earlier
// Map line item totals based on recurring line totals
switch ($meta_key) {
case '_recurring_line_total':
woocommerce_delete_order_item_meta($recurring_item_id, '_line_total');
woocommerce_update_order_item_meta($recurring_item_id, '_line_total', woocommerce_format_decimal($failed_payment_multiplier * $meta_value));
break;
case '_recurring_line_tax':
woocommerce_delete_order_item_meta($recurring_item_id, '_line_tax');
woocommerce_update_order_item_meta($recurring_item_id, '_line_tax', woocommerce_format_decimal($failed_payment_multiplier * $meta_value));
break;
case '_recurring_line_subtotal':
woocommerce_delete_order_item_meta($recurring_item_id, '_line_subtotal');
woocommerce_update_order_item_meta($recurring_item_id, '_line_subtotal', woocommerce_format_decimal($failed_payment_multiplier * $meta_value));
break;
case '_recurring_line_subtotal_tax':
woocommerce_delete_order_item_meta($recurring_item_id, '_line_subtotal_tax');
开发者ID:jgabrielfreitas,项目名称:MultipagosTestesAPP,代码行数:67,代码来源:class-wc-subscriptions-renewal-order.php
示例10: upgrade_database_to_1_2
//.........这里部分代码省略.........
$order_taxes = (array) maybe_unserialize($order_tax_row->meta_value);
}
// Set recurring taxes to order taxes, if using WC 2.0, this will be migrated to the new format in @see self::upgrade_to_latest_wc()
update_post_meta($order_id, '_order_recurring_taxes', $order_taxes);
$sign_up_fee_taxes = WC_Subscriptions_Order::get_meta($order, '_sign_up_fee_taxes', array());
// Update order taxes to include sign up fee taxes
foreach ($sign_up_fee_taxes as $index => $sign_up_tax) {
if ($has_trial && $sign_up_fee_total > 0) {
// Order taxes need to be set to the same as the sign up fee taxes
if (isset($sign_up_tax['cart_tax']) && $sign_up_tax['cart_tax'] > 0) {
$order_taxes[$index]['cart_tax'] = $sign_up_tax['cart_tax'];
}
} elseif (!$has_trial && $sign_up_fee_total > 0) {
// Sign up fee taxes need to be added to order taxes
if (isset($sign_up_tax['cart_tax']) && $sign_up_tax['cart_tax'] > 0) {
$order_taxes[$index]['cart_tax'] += $sign_up_tax['cart_tax'];
}
}
}
if (false == self::$is_wc_version_2) {
// Doing it right: updated Subs *before* updating WooCommerce, the WooCommerce updater will take care of data migration
update_post_meta($order_id, '_order_taxes', $order_taxes);
} else {
// Doing it wrong: updated Subs *after* updating WooCommerce, need to store in WC2.0 tax structure
$index = 0;
$new_order_taxes = $order->get_taxes();
foreach ($new_order_taxes as $item_id => $order_tax) {
$index = $index + 1;
if (!isset($order_taxes[$index]['label']) || !isset($order_taxes[$index]['cart_tax']) || !isset($order_taxes[$index]['shipping_tax'])) {
continue;
}
// Add line item meta
if ($item_id) {
woocommerce_update_order_item_meta($item_id, 'compound', absint(isset($order_taxes[$index]['compound']) ? $order_taxes[$index]['compound'] : 0));
woocommerce_update_order_item_meta($item_id, 'tax_amount', woocommerce_clean($order_taxes[$index]['cart_tax']));
woocommerce_update_order_item_meta($item_id, 'shipping_tax_amount', woocommerce_clean($order_taxes[$index]['shipping_tax']));
}
}
}
/* Upgrade each order item to use new Item Meta schema */
$order_subscription_periods = WC_Subscriptions_Order::get_meta($order_id, '_order_subscription_periods', array());
$order_subscription_intervals = WC_Subscriptions_Order::get_meta($order_id, '_order_subscription_intervals', array());
$order_subscription_lengths = WC_Subscriptions_Order::get_meta($order_id, '_order_subscription_lengths', array());
$order_subscription_trial_lengths = WC_Subscriptions_Order::get_meta($order_id, '_order_subscription_trial_lengths', array());
$order_items = $order->get_items();
foreach ($order_items as $index => $order_item) {
$product_id = WC_Subscriptions_Order::get_items_product_id($order_item);
$item_meta = new WC_Order_Item_Meta($order_item['item_meta']);
$subscription_interval = isset($order_subscription_intervals[$product_id]) ? $order_subscription_intervals[$product_id] : 1;
$subscription_length = isset($order_subscription_lengths[$product_id]) ? $order_subscription_lengths[$product_id] : 0;
$subscription_trial_length = isset($order_subscription_trial_lengths[$product_id]) ? $order_subscription_trial_lengths[$product_id] : 0;
$subscription_sign_up_fee = WC_Subscriptions_Order::get_meta($order, '_cart_contents_sign_up_fee_total', 0);
if ($sign_up_fee_total > 0) {
// Discounted price * Quantity
$sign_up_fee_line_total = WC_Subscriptions_Order::get_meta($order, '_cart_contents_sign_up_fee_total', 0);
$sign_up_fee_line_tax = WC_Subscriptions_Order::get_meta($order, '_sign_up_fee_tax_total', 0);
// Base price * Quantity
$sign_up_fee_line_subtotal = WC_Subscriptions_Order::get_meta($order, '_cart_contents_sign_up_fee_total', 0) + WC_Subscriptions_Order::get_meta($order, '_sign_up_fee_discount_cart', 0);
$sign_up_fee_propotion = $sign_up_fee_line_total > 0 ? $sign_up_fee_line_subtotal / $sign_up_fee_line_total : 0;
$sign_up_fee_line_subtotal_tax = WC_Subscriptions_Manager::get_amount_from_proportion(WC_Subscriptions_Order::get_meta($order, '_sign_up_fee_tax_total', 0), $sign_up_fee_propotion);
if ($has_trial) {
// Set line item totals equal to sign up fee totals
$order_item['line_subtotal'] = $sign_up_fee_line_subtotal;
$order_item['line_subtotal_tax'] = $sign_up_fee_line_subtotal_tax;
$order_item['line_total'] = $sign_up_fee_line_total;
$order_item['line_tax'] = $sign_up_fee_line_tax;
开发者ID:jgabrielfreitas,项目名称:MultipagosTestesAPP,代码行数:67,代码来源:class-wc-subscriptions-upgrader.php
示例11: upd_mem_plan
/** Update Member Plan **/
function upd_mem_plan()
{
global $current_user, $woocommerce, $wpdb;
$mess = array();
$mess['act'] = 'success';
parse_str($_POST['form_data'], $d);
get_currentuserinfo();
$product_id = $d['meal_plan_type'];
$arr = array();
$cur_user_subscription = WC_Subscriptions_Manager::get_users_subscriptions(get_current_user_id());
/* $current_subscription To Cancel all users previous subscription */
foreach ($cur_user_subscription as $suk => $suv) {
$orderID = $suv['order_id'];
$suv['product_id'] = $d['meal_plan'];
$arr[$suv['order_id'] . '_' . $d['meal_plan']] = $suv;
update_user_meta(get_current_user_id(), 'wp_woocommerce_subscriptions', $arr);
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.
$product_id = $d['meal_plan_type'];
$_product = new WC_Product($product_id);
// Set values
$item = array();
// Add line item
$srOW = $wpdb->get_row("select * FROM wp_woocommerce_order_items WHERE order_id = " . $orderID);
$item_id = $srOW->order_item_id;
$args = array('post_type' => 'product', 'post_status' => 'publish');
$loop = new WP_Query($args);
$i = 0;
if ($loop->have_posts()) {
while ($loop->have_posts()) {
$loop->the_post();
$____product = get_product(get_the_ID());
$_var[get_the_ID()] = $____product->get_available_variations();
}
}
wp_reset_query();
foreach ($_var as $_k => $_variations) {
foreach ($_variations as $_vk => $_vv) {
if ($_vv['variation_id'] == $product_id) {
$variation_name = $_vv['attributes']['attribute_servings'];
$p = strip_tags($_vv['price_html']);
}
}
}
// update post meta for pricing
update_post_meta($orderID, '_order_total', get_post_meta($product_id, '_price', true));
update_post_meta($orderID, '_order_recurring_total', get_post_meta($product_id, '_subscription_price', true));
// Add subscription details so order state persists even when a product is changed
$period = WC_Subscriptions_Product::get_period($product_id);
$interval = WC_Subscriptions_Product::get_interval($product_id);
$length = WC_Subscriptions_Product::get_length($product_id);
$trial_length = WC_Subscriptions_Product::get_trial_length($product_id);
$trial_period = WC_Subscriptions_Product::get_trial_period($product_id);
$sign_up_fee = WC_Subscriptions_Product::get_sign_up_fee($product_id);
woocommerce_update_order_item_meta($item_id, '_qty', 1);
woocommerce_update_order_item_meta($item_id, '_tax_class', '');
woocommerce_update_order_item_meta($item_id, '_product_id', $d['meal_plan']);
woocommerce_update_order_item_meta($item_id, '_variation_id', $product_id);
woocommerce_update_order_item_meta($item_id, '_line_subtotal', get_post_meta($product_id, '_price', true));
woocommerce_update_order_item_meta($item_id, '_line_total', get_post_meta($product_id, '_subscription_price', true));
// WC_Subscriptions_Product::get_price() would return a price without filters applied
woocommerce_update_order_item_meta($item_id, '_line_tax', 0);
woocommerce_update_order_item_meta($item_id, '_line_subtotal_tax', 0);
// WC_Subscriptions_Product::get_price() would return a price without filters applied
woocommerce_update_order_item_meta($item_id, 'Servings:', $variation_name);
woocommerce_update_order_item_meta($item_id, '_subscription_period', $period);
woocommerce_update_order_item_meta($item_id, '_subscription_interval', $interval);
woocommerce_update_order_item_meta($item_id, '_subscription_length', $length);
woocommerce_update_order_item_meta($item_id, '_subscription_trial_length', $trial_length);
woocommerce_update_order_item_meta($item_id, '_subscription_trial_period', $trial_period);
woocommerce_update_order_item_meta($item_id, '_subscription_recurring_amount', get_post_meta($product_id, '_subscription_price', true));
// WC_Subscriptions_Product::get_price() would return a price without filters applied
woocommerce_update_order_item_meta($item_id, '_subscription_sign_up_fee', $sign_up_fee);
// Calculated recurring amounts for the item
woocommerce_update_order_item_meta($item_id, '_recurring_line_total', number_format((double) get_post_meta($product_id, '_price', true), 2, '.', ''));
woocommerce_update_order_item_meta($item_id, '_recurring_line_tax', '');
woocommerce_update_order_item_meta($item_id, '_recurring_line_subtotal', number_format((double) get_post_meta($product_id, '_regular_price', true), 2, '.', ''));
woocommerce_update_order_item_meta($item_id, '_recurring_line_subtotal_tax', '');
$odr = $orderID;
/* Fetch Oder Details */
//if(($_vv['variation_id'] == $vari_ID))
$mealOrder = woocommerce_get_order_item_meta($srOW->order_item_id, 'Servings:', true);
$mealType = woocommerce_get_order_item_meta($srOW->order_item_id, '_subscription_period', true);
$mealTotal = woocommerce_get_order_item_meta($srOW->order_item_id, '_recurring_line_subtotal', true);
$vari_ID = woocommerce_get_order_item_meta($srOW->order_item_id, '_variation_id', true);
$_product = get_product($product_id);
$srOW = $wpdb->get_row("UPDATE wp_woocommerce_order_items SET order_item_name = '" . $_product->post->post_title . "' WHERE order_item_id=" . $item_id);
$html = '<div class="info_heading">Meal Plan</div>
<div class="info_values">
<p>' . $_product->post->post_title . '</p>
</div>
<div class="info_heading">Subscriptions Type</div>
<div class="info_values">
<p>' . $variation_name . '</p>
</div>
<div class="info_heading">Price</div>
<div class="info_values">
<p>' . $p . '</p>
//.........这里部分代码省略.........
开发者ID:bulats,项目名称:chef,代码行数:101,代码来源:functions.php
示例12: pre_process_shop_order_meta
/**
* When an order is added or updated from the admin interface, check if a subscription product
* has been manually added to the order or the details of the subscription have been modified,
* and create/update the subscription as required.
*
* Save subscription order meta items
*
* @param $post_id int The ID of the post which is the WC_Order object.
* @param $post Object The post object of the order.
* @since 1.1
*/
public static function pre_process_shop_order_meta($post_id, $post)
{
global $woocommerce, $wpdb;
$order_contains_subscription = false;
$order = new WC_Order($post_id);
$existing_product_ids = array();
foreach ($order->get_items() as $existing_item) {
$existing_product_ids[] = self::get_items_product_id($existing_item);
}
$product_ids = array();
// WC <> 2.0 compatible posted product IDs
if (isset($_POST['order_item_id'])) {
foreach ($_POST['order_item_id'] as $order_item_id) {
// WC 2.0+ has unique order item IDs and the product ID is a piece of meta
$product_ids[$order_item_id] = woocommerce_get_order_item_meta($order_item_id, '_product_id');
}
} elseif (isset($_POST['item_id'])) {
$product_ids = $_POST['item_id'];
}
// WC 1.x treated order item IDs as product IDs
// Check if there are new subscription products to be added, or the order already has a subscription item
foreach (array_merge($product_ids, $existing_product_ids) as $order_item_id => $product_id) {
$is_existing_item = false;
if (in_array($product_id, $existing_product_ids)) {
$is_existing_item = true;
}
// If this is a new item and it's a subscription product, we have a subscription
if (!$is_existing_item && WC_Subscriptions_Product::is_subscription($product_id)) {
$order_contains_subscription = true;
}
// If this is an existing item and it's a subscription item, we have a subscription
if ($is_existing_item && WC_Subscriptions_Order::is_item_subscription($order, $product_id)) {
$order_contains_subscription = true;
}
}
if (!$order_contains_subscription) {
return $post_id;
}
// If the payment method is changing, make sure we have correct manual payment flag set
$chosen_payment_method = stripslashes($_POST['_payment_method']);
$existing_payment_method = get_post_meta($post_id, '_payment_method', true);
if ($chosen_payment_method != $existing_payment_method || empty($chosen_payment_method)) {
$payment_gateways = $woocommerce->payment_gateways->payment_gateways();
if (
|
请发表评论