本文整理汇总了PHP中WC_Subscriptions_Product::get_trial_period方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Subscriptions_Product::get_trial_period方法的具体用法?PHP WC_Subscriptions_Product::get_trial_period怎么用?PHP WC_Subscriptions_Product::get_trial_period使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WC_Subscriptions_Product
的用法示例。
在下文中一共展示了WC_Subscriptions_Product::get_trial_period方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_cart_subscription_trial_period
/**
* Gets the subscription trial period from the cart and returns it as an array (eg. array( 'month', 'day' ) )
*
* @since 1.2
*/
public static function get_cart_subscription_trial_period()
{
global $woocommerce;
$trial_period = '';
// Get the original trial period
foreach ($woocommerce->cart->cart_contents as $cart_item) {
$item_id = empty($cart_item['variation_id']) ? $cart_item['product_id'] : $cart_item['variation_id'];
if (isset($cart_item['data']->subscription_trial_period)) {
$trial_period = $cart_item['data']->subscription_trial_period;
break;
} elseif (WC_Subscriptions_Product::is_subscription($item_id)) {
$trial_period = WC_Subscriptions_Product::get_trial_period($item_id);
break;
}
}
return apply_filters('woocommerce_subscriptions_cart_trial_period', $trial_period);
}
示例2: calculate_first_payment_date
/**
* Calculate the first payment date for a synced subscription.
*
* The date is calculated in UTC timezone.
*
* @param WC_Product $product A subscription product.
* @param string $type (optional) The format to return the first payment date in, either 'mysql' or 'timestamp'. Default 'mysql'.
* @param string $from_date (optional) The date to calculate the first payment from in GMT/UTC timzeone. If not set, it will use the current date. This should not include any trial period on the product.
* @since 1.5
*/
public static function calculate_first_payment_date($product, $type = 'mysql', $from_date = '')
{
if (!is_object($product)) {
$product = WC_Subscriptions::get_product($product);
}
if (!self::is_product_synced($product)) {
return 0;
}
$period = WC_Subscriptions_Product::get_period($product);
$trial_period = WC_Subscriptions_Product::get_trial_period($product);
$trial_length = WC_Subscriptions_Product::get_trial_length($product);
$from_date_param = $from_date;
if (empty($from_date)) {
$from_date = gmdate('Y-m-d H:i:s');
}
// If the subscription has a free trial period, the first payment should be synced to a day after the free trial
if ($trial_length > 0) {
$from_date = WC_Subscriptions_Product::get_trial_expiration_date($product, $from_date);
}
$from_timestamp = strtotime($from_date) + get_option('gmt_offset') * 3600;
// Site time
$payment_day = self::get_products_payment_day($product);
if ('week' == $period) {
// strtotime() only handles English, so can't use $wp_locale->weekday here
$weekdays = array(1 => 'Monday', 2 => 'Tuesday', 3 => 'Wednesday', 4 => 'Thursday', 5 => 'Friday', 6 => 'Saturday', 7 => 'Sunday');
// strtotime() will figure out if the day is in the future or today (see: https://gist.github.com/thenbrent/9698083)
$first_payment_timestamp = strtotime($weekdays[$payment_day], $from_timestamp);
} elseif ('month' == $period) {
// strtotime() needs to know the month, so we need to determine if the specified day has occured this month yet or if we want the last day of the month (see: https://gist.github.com/thenbrent/9698083)
if ($payment_day > 27) {
// we actually want the last day of the month
$payment_day = gmdate('t', $from_timestamp);
$month = gmdate('F', $from_timestamp);
} elseif (gmdate('j', $from_timestamp) > $payment_day) {
// today is later than specified day in the from date, we need the next month
$month = date('F', WC_Subscriptions::add_months($from_timestamp, 1));
} else {
// specified day is either today or still to come in the month of the from date
$month = gmdate('F', $from_timestamp);
}
$first_payment_timestamp = strtotime("{$payment_day} {$month}", $from_timestamp);
} elseif ('year' == $period) {
// We can't use $wp_locale here because it is translated
switch ($payment_day['month']) {
case 1:
$month = 'January';
break;
case 2:
$month = 'February';
break;
case 3:
$month = 'March';
break;
case 4:
$month = 'April';
break;
case 5:
$month = 'May';
break;
case 6:
$month = 'June';
break;
case 7:
$month = 'July';
break;
case 8:
$month = 'August';
break;
case 9:
$month = 'September';
break;
case 10:
$month = 'October';
break;
case 11:
$month = 'November';
break;
case 12:
$month = 'December';
break;
}
$first_payment_timestamp = strtotime("{$payment_day['day']} {$month}", $from_timestamp);
}
// Make sure the next payment is in the future and after the $from_date, as strtotime() will return the date this year for any day in the past when adding months or years (see: https://gist.github.com/thenbrent/9698083)
if ('year' == $period || 'month' == $period) {
// First make sure the day is in the past so that we don't end up jumping a month or year because of a few hours difference between now and the billing date
if (gmdate('j', $first_payment_timestamp) < gmdate('j') && gmdate('n', $first_payment_timestamp) <= gmdate('n') && gmdate('Y', $first_payment_timestamp) <= gmdate('Y')) {
$i = 1;
// Then make sure the date and time of the payment is in the future
while (($first_payment_timestamp < gmdate('U') || $first_payment_timestamp < $from_timestamp) && $i < 30) {
//.........这里部分代码省略.........
示例3: variable_subscription_pricing_fields
/**
* Output the subscription specific pricing fields on the "Edit Product" admin page.
*
* @since 1.3
*/
public static function variable_subscription_pricing_fields($loop, $variation_data, $variation)
{
global $woocommerce, $thepostid;
// Set month as the default billing period
if (!($subscription_period = get_post_meta($variation->ID, '_subscription_period', true))) {
$subscription_period = 'month';
}
// When called via Ajax
if (!function_exists('woocommerce_wp_text_input')) {
require_once $woocommerce->plugin_path() . '/admin/post-types/writepanels/writepanels-init.php';
}
if (!isset($thepostid)) {
$thepostid = $variation->post_parent;
}
?>
<tr class="variable_subscription_pricing show_if_variable-subscription">
<td colspan="2">
<label><?php
printf(__('Subscription Price (%s)', WC_Subscriptions::$text_domain), get_woocommerce_currency_symbol());
?>
</label>
<?php
// Subscription Price
woocommerce_wp_text_input(array('id' => 'variable_subscription_price[' . $loop . ']', 'class' => 'wc_input_subscription_price', 'wrapper_class' => '_subscription_price_field', 'label' => sprintf(__('Subscription Price (%s)', WC_Subscriptions::$text_domain), get_woocommerce_currency_symbol()), 'placeholder' => __('e.g. 5.90', WC_Subscriptions::$text_domain), 'value' => get_post_meta($variation->ID, '_subscription_price', true), 'type' => 'number', 'custom_attributes' => array('step' => 'any', 'min' => '0')));
// Subscription Period Interval
woocommerce_wp_select(array('id' => 'variable_subscription_period_interval[' . $loop . ']', 'class' => 'wc_input_subscription_period_interval', 'wrapper_class' => '_subscription_period_interval_field', 'label' => __('Subscription Periods', WC_Subscriptions::$text_domain), 'options' => WC_Subscriptions_Manager::get_subscription_period_interval_strings(), 'value' => get_post_meta($variation->ID, '_subscription_period_interval', true)));
// Billing Period
woocommerce_wp_select(array('id' => 'variable_subscription_period[' . $loop . ']', 'class' => 'wc_input_subscription_period', 'wrapper_class' => '_subscription_period_field', 'label' => __('Billing Period', WC_Subscriptions::$text_domain), 'value' => $subscription_period, 'description' => __('for', WC_Subscriptions::$text_domain), 'options' => WC_Subscriptions_Manager::get_subscription_period_strings()));
// Subscription Length
woocommerce_wp_select(array('id' => 'variable_subscription_length[' . $loop . ']', 'class' => 'wc_input_subscription_length', 'wrapper_class' => '_subscription_length_field', 'label' => __('Subscription Length', WC_Subscriptions::$text_domain), 'options' => WC_Subscriptions_Manager::get_subscription_ranges($subscription_period), 'value' => get_post_meta($variation->ID, '_subscription_length', true)));
?>
</td>
<td class="sign-up-fee-cell show_if_variable-subscription">
<label><?php
printf(__('Sign-up Fee (%s)', WC_Subscriptions::$text_domain), get_woocommerce_currency_symbol());
?>
</label>
<?php
// Sign-up Fee
woocommerce_wp_text_input(array('id' => 'variable_subscription_sign_up_fee[' . $loop . ']', 'class' => 'wc_input_subscription_intial_price', 'wrapper_class' => '_subscription_sign_up_fee_field', 'label' => sprintf(__('Sign-up Fee (%s)', WC_Subscriptions::$text_domain), get_woocommerce_currency_symbol()), 'placeholder' => __('e.g. 9.90', WC_Subscriptions::$text_domain), 'value' => get_post_meta($variation->ID, '_subscription_sign_up_fee', true), 'type' => 'number', 'custom_attributes' => array('step' => 'any', 'min' => '0')));
?>
</td>
</tr>
<tr class="variable_subscription_trial show_if_variable-subscription">
<td colspan="1" class="show_if_variable-subscription">
<label><?php
_e('Free Trial', WC_Subscriptions::$text_domain);
?>
</label>
<?php
// Trial Length
woocommerce_wp_text_input(array('id' => 'variable_subscription_trial_length[' . $loop . ']', 'class' => 'wc_input_subscription_trial_length', 'wrapper_class' => '_subscription_trial_length_field', 'label' => __('Free Trial', WC_Subscriptions::$text_domain), 'placeholder' => __('e.g. 3', WC_Subscriptions::$text_domain), 'value' => get_post_meta($variation->ID, '_subscription_trial_length', true)));
// Trial Period
woocommerce_wp_select(array('id' => 'variable_subscription_trial_period[' . $loop . ']', 'class' => 'wc_input_subscription_trial_period', 'wrapper_class' => '_subscription_trial_period_field', 'label' => __('Subscription Trial Period', WC_Subscriptions::$text_domain), 'options' => WC_Subscriptions_Manager::get_available_time_periods(), 'description' => sprintf(__('An optional period of time to wait before charging the first recurring payment. Any sign up fee will still be charged at the outset of the subscription. %s', WC_Subscriptions::$text_domain), self::get_trial_period_validation_message()), 'desc_tip' => true, 'value' => WC_Subscriptions_Product::get_trial_period($variation->ID)));
do_action('woocommerce_variable_subscription_pricing');
?>
</td>
</tr>
<?php
}
示例4: subscription_pricing_fields
/**
* Output the subscription specific pricing fields on the "Edit Product" admin page.
*
* @since 1.0
*/
public static function subscription_pricing_fields()
{
global $post;
// Set month as the default billing period
if (!($subscription_period = get_post_meta($post->ID, '_subscription_period', true))) {
$subscription_period = 'month';
}
echo '<div class="options_group subscription_pricing show_if_subscription">';
// Subscription Price
woocommerce_wp_text_input(array('id' => '_subscription_price', 'class' => 'wc_input_subscription_price', 'label' => sprintf(__('Subscription Price (%s)', 'woocommerce-subscriptions'), get_woocommerce_currency_symbol()), 'placeholder' => _x('e.g. 9.90', 'example price', 'woocommerce-subscriptions'), 'type' => 'text', 'custom_attributes' => array('step' => 'any', 'min' => '0')));
// Subscription Period Interval
woocommerce_wp_select(array('id' => '_subscription_period_interval', 'class' => 'wc_input_subscription_period_interval', 'label' => __('Subscription Periods', 'woocommerce-subscriptions'), 'options' => wcs_get_subscription_period_interval_strings()));
// Billing Period
woocommerce_wp_select(array('id' => '_subscription_period', 'class' => 'wc_input_subscription_period', 'label' => __('Billing Period', 'woocommerce-subscriptions'), 'value' => $subscription_period, 'description' => _x('for', 'for in "Every month _for_ 12 months"', 'woocommerce-subscriptions'), 'options' => wcs_get_subscription_period_strings()));
// Subscription Length
woocommerce_wp_select(array('id' => '_subscription_length', 'class' => 'wc_input_subscription_length', 'label' => __('Subscription Length', 'woocommerce-subscriptions'), 'options' => wcs_get_subscription_ranges($subscription_period)));
// Sign-up Fee
woocommerce_wp_text_input(array('id' => '_subscription_sign_up_fee', 'class' => 'wc_input_subscription_intial_price', 'label' => sprintf(__('Sign-up Fee (%s)', 'woocommerce-subscriptions'), get_woocommerce_currency_symbol()), 'placeholder' => _x('e.g. 9.90', 'example price', 'woocommerce-subscriptions'), 'description' => __('Optionally include an amount to be charged at the outset of the subscription. The sign-up fee will be charged immediately, even if the product has a free trial or the payment dates are synced.', 'woocommerce-subscriptions'), 'desc_tip' => true, 'type' => 'text', 'custom_attributes' => array('step' => 'any', 'min' => '0')));
// Trial Length
woocommerce_wp_text_input(array('id' => '_subscription_trial_length', 'class' => 'wc_input_subscription_trial_length', 'label' => __('Free Trial', 'woocommerce-subscriptions')));
// Trial Period
woocommerce_wp_select(array('id' => '_subscription_trial_period', 'class' => 'wc_input_subscription_trial_period', 'label' => __('Subscription Trial Period', 'woocommerce-subscriptions'), 'options' => wcs_get_available_time_periods(), 'description' => sprintf(_x('An optional period of time to wait before charging the first recurring payment. Any sign up fee will still be charged at the outset of the subscription. %s', 'Trial period dropdown\'s description in pricing fields', 'woocommerce-subscriptions'), self::get_trial_period_validation_message()), 'desc_tip' => true, 'value' => WC_Subscriptions_Product::get_trial_period($post->ID)));
do_action('woocommerce_subscriptions_product_options_pricing');
wp_nonce_field('wcs_subscription_meta', '_wcsnonce');
echo '</div>';
echo '<div class="show_if_subscription clear"></div>';
}
示例5: subscription_pricing_fields
/**
* Output the subscription specific pricing fields on the "Edit Product" admin page.
*
* @since 1.0
*/
public static function subscription_pricing_fields()
{
global $post;
// Set month as the default billing period
if (!($subscription_period = get_post_meta($post->ID, '_subscription_period', true))) {
$subscription_period = 'month';
}
echo '<div class="options_group show_if_subscription subscription_pricing">';
// Subscription Price
woocommerce_wp_text_input(array('id' => '_subscription_price', 'class' => 'wc_input_subscription_price', 'label' => sprintf(__('Subscription Price (%s)', WC_Subscriptions::$text_domain), get_woocommerce_currency_symbol()), 'placeholder' => __('e.g. 5.90', WC_Subscriptions::$text_domain)));
// Subscription Period Interval
woocommerce_wp_select(array('id' => '_subscription_period_interval', 'class' => 'wc_input_subscription_period_interval', 'label' => __('Subscription Periods', WC_Subscriptions::$text_domain), 'options' => WC_Subscriptions_Manager::get_subscription_period_interval_strings()));
// Billing Period
woocommerce_wp_select(array('id' => '_subscription_period', 'class' => 'wc_input_subscription_period', 'label' => __('Billing Period', WC_Subscriptions::$text_domain), 'value' => $subscription_period, 'description' => __('for', WC_Subscriptions::$text_domain), 'options' => WC_Subscriptions_Manager::get_subscription_period_strings()));
// Subscription Length
woocommerce_wp_select(array('id' => '_subscription_length', 'class' => 'wc_input_subscription_length', 'label' => __('Subscription Length', WC_Subscriptions::$text_domain), 'options' => WC_Subscriptions_Manager::get_subscription_ranges($subscription_period), 'description' => sprintf(__('with a %s', WC_Subscriptions::$text_domain), get_woocommerce_currency_symbol())));
// Sign-up Fee
woocommerce_wp_text_input(array('id' => '_subscription_sign_up_fee', 'class' => 'wc_input_subscription_intial_price', 'label' => sprintf(__('Sign-up Fee (%s)', WC_Subscriptions::$text_domain), get_woocommerce_currency_symbol()), 'placeholder' => __('e.g. 9.90', WC_Subscriptions::$text_domain), 'description' => __('sign-up fee', WC_Subscriptions::$text_domain)));
// Trial Length
woocommerce_wp_text_input(array('id' => '_subscription_trial_length', 'class' => 'wc_input_subscription_trial_length', 'label' => __('Free Trial', WC_Subscriptions::$text_domain)));
// Trial Period
woocommerce_wp_select(array('id' => '_subscription_trial_period', 'class' => 'wc_input_subscription_trial_period', 'label' => __('Subscription Trial Period', WC_Subscriptions::$text_domain), 'options' => WC_Subscriptions_Manager::get_available_time_periods(), 'description' => sprintf(__('Include an optional period of time to wait before charging the first recurring payment. Any sign up fee will still be charged at the outset of the subscription. %s', WC_Subscriptions::$text_domain), self::get_trial_period_validation_message()), 'desc_tip' => true, 'value' => WC_Subscriptions_Product::get_trial_period($post->ID)));
do_action('woocommerce_subscriptions_product_options_pricing');
echo '</div>';
echo '<div class="show_if_subscription clear"></div>';
}
示例6: 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);
}
}
示例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;
}
示例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_trial_period
/**
* Gets the subscription trial 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 trial period for the entire cart.
*
* @since 1.2
* @deprecated 2.0
*/
public static function get_cart_subscription_trial_period()
{
_deprecated_function(__METHOD__, '2.0', 'values from WC()->cart->recurring_carts');
$trial_period = '';
// Get the original trial period
if (self::cart_contains_subscription()) {
foreach (WC()->cart->cart_contents as $cart_item) {
if (isset($cart_item['data']->subscription_trial_period)) {
$trial_period = $cart_item['data']->subscription_trial_period;
break;
} elseif (WC_Subscriptions_Product::is_subscription($cart_item['data'])) {
$trial_period = WC_Subscriptions_Product::get_trial_period($cart_item['data']);
break;
}
}
}
return apply_filters('woocommerce_subscriptions_cart_trial_period', $trial_period);
}
示例10: get_post_meta
<?php
/**
* Outputs a subscription variation's pricing fields for WooCommerce 2.3
*
* @var int $loop
* @var WP_POST $variation
* @var string $subscription_period
* @var array $variation_data array of variation data
*/
if (!defined('ABSPATH')) {
exit;
}
$chosen_interval = get_post_meta($variation->ID, '_subscription_period_interval', true);
$chosen_length = get_post_meta($variation->ID, '_subscription_length', true);
$chosen_trial_period = WC_Subscriptions_Product::get_trial_period($variation->ID);
?>
<div class="variable_subscription_trial variable_subscription_pricing_2_3 show_if_variable-subscription variable_subscription_trial_sign_up">
<p class="form-row form-row-first form-field show_if_variable-subscription sign-up-fee-cell">
<label for="variable_subscription_sign_up_fee[<?php
echo esc_attr($loop);
?>
]"><?php
printf(esc_html__('Sign-up Fee: (%s)', 'woocommerce-subscriptions'), esc_html(get_woocommerce_currency_symbol()));
?>
</label>
<input type="text" class="wc_input_subscription_intial_price" name="variable_subscription_sign_up_fee[<?php
echo esc_attr($loop);
?>
]" value="<?php
echo esc_attr(get_post_meta($variation->ID, '_subscription_sign_up_fee', true));
示例11: get_cart_subscription_trial_period
/**
* Gets the subscription trial period from the cart and returns it as an array (eg. array( 'month', 'day' ) )
*
* @since 1.2
*/
public static function get_cart_subscription_trial_period()
{
global $woocommerce;
$trial_period = '';
foreach ($woocommerce->cart->cart_contents as $cart_item) {
if (WC_Subscriptions_Product::is_subscription($cart_item['product_id'])) {
$trial_period = WC_Subscriptions_Product::get_trial_period($cart_item['product_id']);
break;
}
}
return $trial_period;
}
示例12: 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>
//.........这里部分代码省略.........
示例13: 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;
}
示例14: woocommerce_wp_text_input
woocommerce_wp_text_input(array('id' => 'variable_subscription_price[' . $loop . ']', 'class' => 'wc_input_subscription_price', 'wrapper_class' => '_subscription_price_field', 'label' => sprintf(__('Subscription Price (%s)', 'woocommerce-subscriptions'), get_woocommerce_currency_symbol()), 'placeholder' => _x('e.g. 9.90', 'example price', 'woocommerce-subscriptions'), 'value' => get_post_meta($variation->ID, '_subscription_price', true), 'type' => 'number', 'custom_attributes' => array('step' => 'any', 'min' => '0')));
// Subscription Period Interval
woocommerce_wp_select(array('id' => 'variable_subscription_period_interval[' . $loop . ']', 'class' => 'wc_input_subscription_period_interval', 'wrapper_class' => '_subscription_period_interval_field', 'label' => __('Subscription Periods', 'woocommerce-subscriptions'), 'options' => wcs_get_subscription_period_interval_strings(), 'value' => get_post_meta($variation->ID, '_subscription_period_interval', true)));
// Billing Period
woocommerce_wp_select(array('id' => 'variable_subscription_period[' . $loop . ']', 'class' => 'wc_input_subscription_period', 'wrapper_class' => '_subscription_period_field', 'label' => __('Billing Period', 'woocommerce-subscriptions'), 'value' => $subscription_period, 'description' => _x('for', 'Edit product screen, between the Billing Period and Subscription Length dropdowns', 'woocommerce-subscriptions'), 'options' => wcs_get_subscription_period_strings()));
// Subscription Length
woocommerce_wp_select(array('id' => 'variable_subscription_length[' . $loop . ']', 'class' => 'wc_input_subscription_length', 'wrapper_class' => '_subscription_length_field', 'label' => __('Subscription Length', 'woocommerce-subscriptions'), 'options' => wcs_get_subscription_ranges($subscription_period), 'value' => get_post_meta($variation->ID, '_subscription_length', true)));
?>
</td>
</tr>
<tr class="variable_subscription_trial show_if_variable-subscription variable_subscription_trial_sign_up">
<td class="sign-up-fee-cell show_if_variable-subscription">
<?php
// Sign-up Fee
woocommerce_wp_text_input(array('id' => 'variable_subscription_sign_up_fee[' . $loop . ']', 'class' => 'wc_input_subscription_intial_price', 'wrapper_class' => '_subscription_sign_up_fee_field', 'label' => sprintf(__('Sign-up Fee (%s)', 'woocommerce-subscriptions'), get_woocommerce_currency_symbol()), 'placeholder' => _x('e.g. 9.90', 'example price', 'woocommerce-subscriptions'), 'value' => get_post_meta($variation->ID, '_subscription_sign_up_fee', true), 'type' => 'number', 'custom_attributes' => array('step' => 'any', 'min' => '0')));
?>
</td>
<td colspan="1" class="show_if_variable-subscription">
<label><?php
esc_html_e('Free Trial', 'woocommerce-subscriptions');
?>
</label>
<?php
// Trial Length
woocommerce_wp_text_input(array('id' => 'variable_subscription_trial_length[' . $loop . ']', 'class' => 'wc_input_subscription_trial_length', 'wrapper_class' => '_subscription_trial_length_field', 'label' => __('Free Trial', 'woocommerce-subscriptions'), 'placeholder' => _x('e.g. 3', 'example number of days / weeks / months', 'woocommerce-subscriptions'), 'value' => get_post_meta($variation->ID, '_subscription_trial_length', true)));
// Trial Period
woocommerce_wp_select(array('id' => 'variable_subscription_trial_period[' . $loop . ']', 'class' => 'wc_input_subscription_trial_period', 'wrapper_class' => '_subscription_trial_period_field', 'label' => __('Subscription Trial Period', 'woocommerce-subscriptions'), 'options' => wcs_get_available_time_periods(), 'description' => sprintf(_x('An optional period of time to wait before charging the first recurring payment. Any sign up fee will still be charged at the outset of the subscription. %s', 'Trial period dropdown\'s description in pricing fields', 'woocommerce-subscriptions'), self::get_trial_period_validation_message()), 'desc_tip' => true, 'value' => WC_Subscriptions_Product::get_trial_period($variation->ID)));
?>
</td>
</tr>