本文整理汇总了PHP中WC_Subscriptions_Product::get_interval方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Subscriptions_Product::get_interval方法的具体用法?PHP WC_Subscriptions_Product::get_interval怎么用?PHP WC_Subscriptions_Product::get_interval使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WC_Subscriptions_Product
的用法示例。
在下文中一共展示了WC_Subscriptions_Product::get_interval方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: add_order_meta
/**
* When a new order is inserted, add the subscriptions period to the order.
*
* It's important that the period is tied to the order so that changing the products
* period does not change the past.
*
* @since 1.0
*/
public static function add_order_meta($order_id)
{
global $woocommerce;
if (WC_Subscriptions_Order::order_contains_subscription($order_id)) {
$order = new WC_Order($order_id);
$order_subscription_periods = array();
$order_subscription_intervals = array();
$order_subscription_lengths = array();
$order_subscription_trial_lengths = array();
foreach ($order->get_items() as $item) {
$period = WC_Subscriptions_Product::get_period($item['id']);
if (!empty($period)) {
$order_subscription_periods[$item['id']] = $period;
}
$interval = WC_Subscriptions_Product::get_interval($item['id']);
if (!empty($interval)) {
$order_subscription_intervals[$item['id']] = $interval;
}
$length = WC_Subscriptions_Product::get_length($item['id']);
if (!empty($length)) {
$order_subscription_lengths[$item['id']] = $length;
}
$trial_length = WC_Subscriptions_Product::get_trial_length($item['id']);
if (!empty($trial_length)) {
$order_subscription_trial_lengths[$item['id']] = $trial_length;
}
}
update_post_meta($order_id, '_order_subscription_periods', $order_subscription_periods);
update_post_meta($order_id, '_order_subscription_intervals', $order_subscription_intervals);
update_post_meta($order_id, '_order_subscription_lengths', $order_subscription_lengths);
update_post_meta($order_id, '_order_subscription_trial_lengths', $order_subscription_trial_lengths);
// Store sign-up fee details
foreach (WC_Subscriptions_Cart::get_sign_up_fee_fields() as $field_name) {
update_post_meta($order_id, "_{$field_name}", $woocommerce->cart->{$field_name});
}
// Prepare sign up fee taxes to store in same format as order taxes
$sign_up_fee_taxes = array();
foreach (array_keys($woocommerce->cart->sign_up_fee_taxes) as $key) {
$is_compound = $woocommerce->cart->tax->is_compound($key) ? 1 : 0;
$sign_up_fee_taxes[] = array('label' => $woocommerce->cart->tax->get_rate_label($key), 'compound' => $is_compound, 'cart_tax' => number_format($woocommerce->cart->sign_up_fee_taxes[$key], 2, '.', ''));
}
update_post_meta($order_id, '_sign_up_fee_taxes', $sign_up_fee_taxes);
}
}
示例2: get_cart_subscription_interval
/**
* Gets the subscription period from the cart and returns it as an array (eg. array( 'month', 'day' ) )
*
* @since 1.0
*/
public static function get_cart_subscription_interval()
{
global $woocommerce;
foreach ($woocommerce->cart->cart_contents as $cart_item) {
$item_id = empty($cart_item['variation_id']) ? $cart_item['product_id'] : $cart_item['variation_id'];
if (WC_Subscriptions_Product::is_subscription($item_id)) {
$interval = WC_Subscriptions_Product::get_interval($item_id);
break;
}
}
return apply_filters('woocommerce_subscriptions_cart_interval', $interval);
}
示例3: create_pending_subscription_for_order
/**
* Uses the details of an order to create a pending subscription on the customers account
* for a subscription product, as specified with $product_id.
*
* @param int|WC_Order $order The order ID or WC_Order object to create the subscription from.
* @param int $product_id The ID of the subscription product on the order, if a variation, it must be the variation's ID.
* @param array $args An array of name => value pairs to customise the details of the subscription, including:
* 'start_date' A MySQL formatted date/time string on which the subscription should start, in UTC timezone
* 'expiry_date' A MySQL formatted date/time string on which the subscription should expire, in UTC timezone
* @since 1.1
*/
public static function create_pending_subscription_for_order($order, $product_id, $args = array())
{
_deprecated_function(__METHOD__, '2.0', 'wcs_create_subscription()');
if (!is_object($order)) {
$order = new WC_Order($order);
}
if (!WC_Subscriptions_Product::is_subscription($product_id)) {
return;
}
$args = wp_parse_args($args, array('start_date' => get_gmt_from_date($order->order_date), 'expiry_date' => ''));
$billing_period = WC_Subscriptions_Product::get_period($product_id);
$billing_interval = WC_Subscriptions_Product::get_interval($product_id);
// Support passing timestamps
$args['start_date'] = is_numeric($args['start_date']) ? date('Y-m-d H:i:s', $args['start_date']) : $args['start_date'];
$product = wc_get_product($product_id);
// Check if there is already a subscription for this product and order
$subscriptions = wcs_get_subscriptions(array('order_id' => $order->id, 'product_id' => $product_id));
if (!empty($subscriptions)) {
$subscription = array_pop($subscriptions);
// Make sure the subscription is pending and start date is set correctly
wp_update_post(array('ID' => $subscription->id, 'post_status' => 'wc-' . apply_filters('woocommerce_default_subscription_status', 'pending'), 'post_date' => get_date_from_gmt($args['start_date'])));
} else {
$subscription = wcs_create_subscription(array('start_date' => get_date_from_gmt($args['start_date']), 'order_id' => $order->id, 'customer_id' => $order->get_user_id(), 'billing_period' => $billing_period, 'billing_interval' => $billing_interval, 'customer_note' => $order->customer_note));
if (is_wp_error($subscription)) {
throw new Exception(__('Error: Unable to create subscription. Please try again.', 'woocommerce-subscriptions'));
}
$item_id = $subscription->add_product($product, 1, array('variation' => method_exists($product, 'get_variation_attributes') ? $product->get_variation_attributes() : array(), 'totals' => array('subtotal' => $product->get_price(), 'subtotal_tax' => 0, 'total' => $product->get_price(), 'tax' => 0, 'tax_data' => array('subtotal' => array(), 'total' => array()))));
if (!$item_id) {
throw new Exception(__('Error: Unable to add product to created subscription. Please try again.', 'woocommerce-subscriptions'));
}
}
// Make sure some of the meta is copied form the order rather than the store's defaults
update_post_meta($subscription->id, '_order_currency', $order->order_currency);
update_post_meta($subscription->id, '_prices_include_tax', $order->prices_include_tax);
// Adding a new subscription so set the expiry date/time from the order date
if (!empty($args['expiry_date'])) {
if (is_numeric($args['expiry_date'])) {
$args['expiry_date'] = date('Y-m-d H:i:s', $args['expiry_date']);
}
$expiration = $args['expiry_date'];
} else {
$expiration = WC_Subscriptions_Product::get_expiration_date($product_id, $args['start_date']);
}
// Adding a new subscription so set the expiry date/time from the order date
$trial_expiration = WC_Subscriptions_Product::get_trial_expiration_date($product_id, $args['start_date']);
$dates_to_update = array();
if ($trial_expiration > 0) {
$dates_to_update['trial_end'] = $trial_expiration;
}
if ($expiration > 0) {
$dates_to_update['end'] = $expiration;
}
if (!empty($dates_to_update)) {
$subscription->update_dates($dates_to_update);
}
// Set the recurring totals on the subscription
$subscription->set_total(0, 'tax');
$subscription->set_total($product->get_price(), 'total');
$subscription->add_order_note(__('Pending subscription created.', 'woocommerce-subscriptions'));
do_action('pending_subscription_created_for_order', $order, $product_id);
}
示例4: 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;
}
示例5: add_order_item_meta
/**
* Add each subscription product's details to an order so that the state of the subscription persists even when a product is changed
*
* @since 1.2.5
*/
public static function add_order_item_meta($item_id, $values)
{
global $woocommerce;
if (!WC_Subscriptions_Cart::cart_contains_subscription_renewal('child') && WC_Subscriptions_Product::is_subscription($values['product_id'])) {
$cart_item = $values['data'];
$product_id = empty($values['variation_id']) ? $values['product_id'] : $values['variation_id'];
// Add subscription details so order state persists even when a product is changed
$period = isset($cart_item->subscription_period) ? $cart_item->subscription_period : WC_Subscriptions_Product::get_period($product_id);
$interval = isset($cart_item->subscription_period_interval) ? $cart_item->subscription_period_interval : WC_Subscriptions_Product::get_interval($product_id);
$length = isset($cart_item->subscription_length) ? $cart_item->subscription_length : WC_Subscriptions_Product::get_length($product_id);
$trial_length = isset($cart_item->subscription_trial_length) ? $cart_item->subscription_trial_length : WC_Subscriptions_Product::get_trial_length($product_id);
$trial_period = isset($cart_item->subscription_trial_period) ? $cart_item->subscription_trial_period : WC_Subscriptions_Product::get_trial_period($product_id);
$sign_up_fee = isset($cart_item->subscription_sign_up_fee) ? $cart_item->subscription_sign_up_fee : WC_Subscriptions_Product::get_sign_up_fee($product_id);
woocommerce_add_order_item_meta($item_id, '_subscription_period', $period);
woocommerce_add_order_item_meta($item_id, '_subscription_interval', $interval);
woocommerce_add_order_item_meta($item_id, '_subscription_length', $length);
woocommerce_add_order_item_meta($item_id, '_subscription_trial_length', $trial_length);
woocommerce_add_order_item_meta($item_id, '_subscription_trial_period', $trial_period);
woocommerce_add_order_item_meta($item_id, '_subscription_recurring_amount', $woocommerce->cart->base_recurring_prices[$product_id]);
// WC_Subscriptions_Product::get_price() would return a price without filters applied
woocommerce_add_order_item_meta($item_id, '_subscription_sign_up_fee', $sign_up_fee);
// Calculated recurring amounts for the item
woocommerce_add_order_item_meta($item_id, '_recurring_line_total', $woocommerce->cart->recurring_cart_contents[$values['product_id']]['recurring_line_total']);
woocommerce_add_order_item_meta($item_id, '_recurring_line_tax', $woocommerce->cart->recurring_cart_contents[$values['product_id']]['recurring_line_tax']);
woocommerce_add_order_item_meta($item_id, '_recurring_line_subtotal', $woocommerce->cart->recurring_cart_contents[$values['product_id']]['recurring_line_subtotal']);
woocommerce_add_order_item_meta($item_id, '_recurring_line_subtotal_tax', $woocommerce->cart->recurring_cart_contents[$values['product_id']]['recurring_line_subtotal_tax']);
// Add recurring line tax data (for WC 2.2+)
$raw_tax_data = $woocommerce->cart->recurring_cart_contents[$values['product_id']]['recurring_line_tax_data'];
$recurring_tax_data = array();
$recurring_tax_data['total'] = array_map('wc_format_decimal', $raw_tax_data['total']);
$recurring_tax_data['subtotal'] = array_map('wc_format_decimal', $raw_tax_data['subtotal']);
woocommerce_add_order_item_meta($item_id, '_recurring_line_tax_data', $recurring_tax_data);
}
}
示例6: get_cart_subscription_interval
/**
* Gets the subscription period from the cart and returns it as an array (eg. array( 'month', 'day' ) )
*
* Deprecated because a cart can now contain multiple subscription products, so there is no single interval for the entire cart.
*
* @since 1.0
* @deprecated 2.0
*/
public static function get_cart_subscription_interval()
{
_deprecated_function(__METHOD__, '2.0', 'values from WC()->cart->recurring_carts');
foreach (WC()->cart->cart_contents as $cart_item) {
if (WC_Subscriptions_Product::is_subscription($cart_item['data'])) {
$interval = WC_Subscriptions_Product::get_interval($cart_item['data']);
break;
}
}
return apply_filters('woocommerce_subscriptions_cart_interval', $interval);
}
示例7: get_subscription
/**
* Return an associative array of a given subscriptions details (if it exists).
*
* @param string $subscription_key A subscription key of the form created by @see self::get_subscription_key()
* @param deprecated don't use
* @return array Subscription details
* @since 1.1
*/
public static function get_subscription($subscription_key, $deprecated = null)
{
if (null != $deprecated) {
_deprecated_argument(__METHOD__, '1.4', __('Second parameter is deprecated', 'woocommerce-subscriptions'));
}
$item = WC_Subscriptions_Order::get_item_by_subscription_key($subscription_key);
if (!empty($item)) {
$subscription = array('order_id' => $item['order_id'], 'product_id' => $item['product_id'], 'variation_id' => $item['variation_id'], 'status' => isset($item['subscription_status']) ? $item['subscription_status'] : 'pending', 'period' => isset($item['subscription_period']) ? $item['subscription_period'] : WC_Subscriptions_Product::get_period($item['product_id']), 'interval' => isset($item['subscription_interval']) ? $item['subscription_interval'] : WC_Subscriptions_Product::get_interval($item['product_id']), 'length' => isset($item['subscription_length']) ? $item['subscription_length'] : WC_Subscriptions_Product::get_length($item['product_id']), 'start_date' => isset($item['subscription_start_date']) ? $item['subscription_start_date'] : 0, 'expiry_date' => isset($item['subscription_expiry_date']) ? $item['subscription_expiry_date'] : 0, 'end_date' => isset($item['subscription_end_date']) ? $item['subscription_end_date'] : 0, 'trial_expiry_date' => isset($item['subscription_trial_expiry_date']) ? $item['subscription_trial_expiry_date'] : 0, 'failed_payments' => isset($item['subscription_failed_payments']) ? $item['subscription_failed_payments'] : 0, 'completed_payments' => isset($item['subscription_completed_payments']) ? $item['subscription_completed_payments'] : array(), 'suspension_count' => isset($item['subscription_suspension_count']) ? $item['subscription_suspension_count'] : 0, 'last_payment_date' => isset($item['subscription_completed_payments']) ? end($item['subscription_completed_payments']) : '');
} else {
$subscription = array();
}
return apply_filters('woocommerce_get_subscription', $subscription, $subscription_key, $deprecated);
}
示例8: add_order_item_meta
/**
* Add each subscription product's details to an order so that the state of the subscription persists even when a product is changed
*
* @since 1.2
*/
public static function add_order_item_meta($order_item)
{
global $woocommerce;
if (WC_Subscriptions_Product::is_subscription($order_item['id'])) {
// Make sure existing meta persists
$item_meta = new WC_Order_Item_Meta($order_item['item_meta']);
// Add subscription details so order state persists even when a product is changed
$item_meta->add('_subscription_period', WC_Subscriptions_Product::get_period($order_item['id']));
$item_meta->add('_subscription_interval', WC_Subscriptions_Product::get_interval($order_item['id']));
$item_meta->add('_subscription_length', WC_Subscriptions_Product::get_length($order_item['id']));
$item_meta->add('_subscription_trial_length', WC_Subscriptions_Product::get_trial_length($order_item['id']));
$item_meta->add('_subscription_trial_period', WC_Subscriptions_Product::get_trial_period($order_item['id']));
$item_meta->add('_subscription_recurring_amount', $woocommerce->cart->base_recurring_prices[$order_item['id']]);
// WC_Subscriptions_Product::get_price() would return a price without filters applied
$item_meta->add('_subscription_sign_up_fee', WC_Subscriptions_Product::get_sign_up_fee($order_item['id']));
// Calculated recurring amounts for the item
$item_meta->add('_recurring_line_total', $woocommerce->cart->recurring_cart_contents[$order_item['id']]['recurring_line_total']);
$item_meta->add('_recurring_line_tax', $woocommerce->cart->recurring_cart_contents[$order_item['id']]['recurring_line_tax']);
$item_meta->add('_recurring_line_subtotal', $woocommerce->cart->recurring_cart_contents[$order_item['id']]['recurring_line_subtotal']);
$item_meta->add('_recurring_line_subtotal_tax', $woocommerce->cart->recurring_cart_contents[$order_item['id']]['recurring_line_subtotal_tax']);
$order_item['item_meta'] = $item_meta->meta;
}
return $order_item;
}
示例9: get_cart_subscription_interval
/**
* Gets the subscription period from the cart and returns it as an array (eg. array( 'month', 'day' ) )
*
* @since 1.0
*/
public static function get_cart_subscription_interval()
{
global $woocommerce;
foreach ($woocommerce->cart->cart_contents as $cart_item) {
if (WC_Subscriptions_Product::is_subscription($cart_item['product_id'])) {
$interval = WC_Subscriptions_Product::get_interval($cart_item['product_id']);
break;
}
}
return $interval;
}
示例10: 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>
//.........这里部分代码省略.........
示例11: prefill_order_item_meta_old
/**
* Add subscription related order item meta via Ajax when a subscription product is added as an item to an order.
*
* This function is hooked to the 'wp_ajax_woocommerce_subscriptions_prefill_order_item_meta' hook which should only fire
* on WC 1.x (because the admin.js uses a selector which was changed in WC 2.0). For WC 2.0, order item meta is pre-filled
* via the 'woocommerce_new_order_item' hook in the new @see self::prefill_order_item().
*
* @since 1.2.4
* @return void
*/
public static function prefill_order_item_meta_old()
{
if (function_exists('woocommerce_add_order_item_meta')) {
// Meta added on the 'woocommerce_new_order_item' hook
return;
}
check_ajax_referer(WC_Subscriptions::$text_domain, 'security');
$product_id = trim(stripslashes($_POST['item_to_add']));
$index = trim(stripslashes($_POST['index']));
$response = array('item_index' => $index, 'html' => '', 'line_totals' => array());
if (WC_Subscriptions_Product::is_subscription($product_id)) {
$recurring_amount = WC_Subscriptions_Product::get_price($product_id);
$item_meta = new WC_Order_Item_Meta();
// Subscription details so order state persists even when a product is changed
$item_meta->add('_subscription_period', WC_Subscriptions_Product::get_period($product_id));
$item_meta->add('_subscription_interval', WC_Subscriptions_Product::get_interval($product_id));
$item_meta->add('_subscription_length', WC_Subscriptions_Product::get_length($product_id));
$item_meta->add('_subscription_trial_length', WC_Subscriptions_Product::get_trial_length($product_id));
$item_meta->add('_subscription_trial_period', WC_Subscriptions_Product::get_trial_period($product_id));
$item_meta->add('_subscription_recurring_amount', $recurring_amount);
$item_meta->add('_subscription_sign_up_fee', WC_Subscriptions_Product::get_sign_up_fee($product_id));
// Recurring totals need to be calcualted
$item_meta->add('_recurring_line_total', $recurring_amount);
$item_meta->add('_recurring_line_tax', 0);
$item_meta->add('_recurring_line_subtotal', $recurring_amount);
$item_meta->add('_recurring_line_subtotal_tax', 0);
$item_meta = $item_meta->meta;
if (isset($item_meta) && is_array($item_meta) && sizeof($item_meta) > 0) {
foreach ($item_meta as $key => $meta) {
// Backwards compatibility
if (is_array($meta) && isset($meta['meta_name'])) {
$meta_name = $meta['meta_name'];
$meta_value = $meta['meta_value'];
} else {
$meta_name = $key;
$meta_value = $meta;
}
$response['html'] .= '<tr><td><input type="text" name="meta_name[' . $index . '][]" value="' . esc_attr($meta_name) . '" /></td><td><input type="text" name="meta_value[' . $index . '][]" value="' . esc_attr($meta_value) . '" /></td><td width="1%"></td></tr>';
}
}
// Calculate line totals for this item
if ($sign_up_fee > 0) {
$line_subtotal = $sign_up_fee;
$line_total = $sign_up_fee;
// If there is no free trial, add the recuring amounts
if ($trial_length == 0) {
$line_subtotal += $recurring_amount;
$line_total += $recurring_amount;
}
$response['line_totals']['line_subtotal'] = esc_attr(number_format((double) $line_subtotal, 2, '.', ''));
$response['line_totals']['line_total'] = esc_attr(number_format((double) $line_total, 2, '.', ''));
}
}
echo json_encode($response);
die;
}
示例12: get_subscription_terms
/**
* Generate Markup for Subscription Periods
*
* @param string $input
* @param obj $product
* @return string
* @access public
* @since 2.0
*/
public static function get_subscription_terms($input = '', $product)
{
$terms = ' ';
if (!is_object($product)) {
$product = wc_nyp_get_product($product);
}
// parent variable subscriptions don't have a billing period, so we get a array to string notice. therefore only apply to simple subs and sub variations
if ($product->is_type('subscription') || $product->is_type('subscription_variation')) {
if (self::is_billing_period_variable($product)) {
// don't display the subscription price, period or length
$include = array('price' => '', 'subscription_price' => false, 'subscription_period' => false);
} else {
$include = array('price' => '', 'subscription_price' => false);
// if we don't show the price we don't get the "per" backslash so add it back
if (WC_Subscriptions_Product::get_interval($product) == 1) {
$terms .= '<span class="per">/ </span>';
}
}
$terms .= WC_Subscriptions_Product::get_price_string($product, $include);
}
// piece it all together - JS needs a span with this class to change terms on variation found event
// use details class to mimic Subscriptions plugin, leave terms class for backcompat
if ('woocommerce_get_price_input' == current_filter()) {
$terms = '<span class="subscription-details subscription-terms">' . $terms . '</span>';
}
return $input . $terms;
}