本文整理汇总了PHP中WC_Subscriptions_Manager::set_trial_expiration_date方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Subscriptions_Manager::set_trial_expiration_date方法的具体用法?PHP WC_Subscriptions_Manager::set_trial_expiration_date怎么用?PHP WC_Subscriptions_Manager::set_trial_expiration_date使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WC_Subscriptions_Manager
的用法示例。
在下文中一共展示了WC_Subscriptions_Manager::set_trial_expiration_date方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process_shop_order_item_meta
/**
* Work around a bug in WooCommerce which ignores order item meta values of 0.
*
* Code in this function is identical to a section of the @see woocommerce_process_shop_order_meta() function, except
* that it doesn't include the bug which ignores item meta with a 0 value.
*
* @param int $post_id The ID of the post which is the WC_Order object.
* @param Object $post The post object of the order.
* @since 1.2.4
*/
public static function process_shop_order_item_meta($post_id, $post)
{
global $woocommerce;
$product_ids = array();
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');
}
}
// Now that meta has been updated, we can update the schedules (if there were any changes to schedule related meta)
if (!empty($product_ids)) {
$user_id = (int) $_POST['customer_user'];
foreach ($product_ids as $product_id) {
$subscription_key = WC_Subscriptions_Manager::get_subscription_key($post_id, $product_id);
// Order is important here, expiration date takes into account trial expriation date and next payment date takes into account expiration date
if (in_array($product_id, self::$requires_update['trial_expiration'])) {
WC_Subscriptions_Manager::set_trial_expiration_date($subscription_key, $user_id);
}
if (in_array($product_id, self::$requires_update['expiration_date'])) {
WC_Subscriptions_Manager::set_expiration_date($subscription_key, $user_id);
}
if (in_array($product_id, self::$requires_update['next_billing_date'])) {
WC_Subscriptions_Manager::set_next_payment_date($subscription_key, $user_id);
}
}
}
}
示例2: process_shop_order_item_meta
/**
* Work around a bug in WooCommerce which ignores order item meta values of 0.
*
* Code in this function is identical to a section of the @see woocommerce_process_shop_order_meta() function, except
* that it doesn't include the bug which ignores item meta with a 0 value.
*
* @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.2.4
*/
public static function process_shop_order_item_meta($post_id, $post)
{
global $woocommerce;
// Only needs to function on WC 1.x where the bug existed
if (isset($_POST['item_id'])) {
$order_items = array();
$item_id = $_POST['item_id'];
$item_variation = $_POST['item_variation'];
$item_name = $_POST['item_name'];
$item_quantity = $_POST['item_quantity'];
$line_subtotal = $_POST['line_subtotal'];
$line_subtotal_tax = $_POST['line_subtotal_tax'];
$line_total = $_POST['line_total'];
$line_tax = $_POST['line_tax'];
$item_meta_names = isset($_POST['meta_name']) ? $_POST['meta_name'] : '';
$item_meta_values = isset($_POST['meta_value']) ? $_POST['meta_value'] : '';
$item_tax_class = $_POST['item_tax_class'];
$item_id_count = sizeof($item_id);
for ($i = 0; $i < $item_id_count; $i++) {
if (!isset($item_id[$i]) || !$item_id[$i]) {
continue;
}
if (!isset($item_name[$i])) {
continue;
}
if (!isset($item_quantity[$i]) || $item_quantity[$i] < 1) {
continue;
}
if (!isset($line_total[$i])) {
continue;
}
if (!isset($line_tax[$i])) {
continue;
}
// Meta
$item_meta = new WC_Order_Item_Meta();
if (isset($item_meta_names[$i]) && isset($item_meta_values[$i])) {
$meta_names = $item_meta_names[$i];
$meta_values = $item_meta_values[$i];
$meta_names_count = sizeof($meta_names);
for ($ii = 0; $ii < $meta_names_count; $ii++) {
$meta_name = esc_attr($meta_names[$ii]);
$meta_value = esc_attr($meta_values[$ii]);
if (isset($meta_name) && isset($meta_value)) {
$item_meta->add($meta_name, $meta_value);
}
}
}
// Add to array
$order_items[] = apply_filters('update_order_item', array('id' => htmlspecialchars(stripslashes($item_id[$i])), 'variation_id' => (int) $item_variation[$i], 'name' => htmlspecialchars(stripslashes($item_name[$i])), 'qty' => (int) $item_quantity[$i], 'line_total' => rtrim(rtrim(number_format(woocommerce_clean($line_total[$i]), 4, '.', ''), '0'), '.'), 'line_tax' => rtrim(rtrim(number_format(woocommerce_clean($line_tax[$i]), 4, '.', ''), '0'), '.'), 'line_subtotal' => rtrim(rtrim(number_format(woocommerce_clean($line_subtotal[$i]), 4, '.', ''), '0'), '.'), 'line_subtotal_tax' => rtrim(rtrim(number_format(woocommerce_clean($line_subtotal_tax[$i]), 4, '.', ''), '0'), '.'), 'item_meta' => $item_meta->meta, 'tax_class' => woocommerce_clean($item_tax_class[$i])));
}
update_post_meta($post_id, '_order_items', $order_items);
}
// WC <> 2.0 compatible posted product IDs
$product_ids = array();
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
// Now that meta has been updated, we can update the schedules (if there were any changes to schedule related meta)
if (!empty($product_ids)) {
$user_id = (int) $_POST['customer_user'];
foreach ($product_ids as $product_id) {
$subscription_key = WC_Subscriptions_Manager::get_subscription_key($post_id, $product_id);
// Order is important here, expiration date takes into account trial expriation date and next payment date takes into account expiration date
if (in_array($product_id, self::$requires_update['trial_expiration'])) {
WC_Subscriptions_Manager::set_trial_expiration_date($subscription_key, $user_id);
}
if (in_array($product_id, self::$requires_update['expiration_date'])) {
WC_Subscriptions_Manager::set_expiration_date($subscription_key, $user_id);
}
if (in_array($product_id, self::$requires_update['next_billing_date'])) {
WC_Subscriptions_Manager::set_next_payment_date($subscription_key, $user_id);
}
}
}
}