本文整理汇总了PHP中wcs_get_subscription函数的典型用法代码示例。如果您正苦于以下问题:PHP wcs_get_subscription函数的具体用法?PHP wcs_get_subscription怎么用?PHP wcs_get_subscription使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wcs_get_subscription函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: cancel_subscriptions
/**
* Find all subscription with a given billing agreement ID and cancel them becasue that billing agreement has been
* cancelled at PayPal, and therefore, no future payments can be charged.
*
* @since 2.0
*/
protected function cancel_subscriptions($billing_agreement_id)
{
$subscription_ids = get_posts(array('posts_per_page' => -1, 'post_type' => 'shop_subscription', 'post_status' => 'any', 'fields' => 'ids', 'orderby' => 'date', 'order' => 'DESC', 'meta_query' => array(array('key' => '_paypal_subscription_id', 'compare' => '=', 'value' => $billing_agreement_id))));
if (empty($subscription_ids)) {
return;
}
$note = esc_html__('Billing agreement cancelled at PayPal.', 'woocommerce-subscriptions');
foreach ($subscription_ids as $subscription_id) {
$subscription = wcs_get_subscription($subscription_id);
try {
if (false !== $subscription && !$subscription->has_status(wcs_get_subscription_ended_statuses())) {
$subscription->cancel_order($note);
WC_Gateway_Paypal::log(sprintf('Subscription %s Cancelled: %s', $subscription_id, $note));
}
} catch (Exception $e) {
WC_Gateway_Paypal::log(sprintf('Unable to cancel subscription %s: %s', $subscription_id, $e->getMessage()));
}
}
}
开发者ID:DustinHartzler,项目名称:TheCLEFT,代码行数:25,代码来源:class-wcs-paypal-reference-transaction-ipn-handler.php
示例2: filter_orders
/**
* Filter the "Orders" list to show only orders associated with a specific subscription.
*
* @param string $where
* @param string $request
* @return string
* @since 2.0
*/
public static function filter_orders($where)
{
global $typenow, $wpdb;
if (is_admin() && 'shop_order' == $typenow) {
$related_orders = array();
if (isset($_GET['_subscription_related_orders']) && $_GET['_subscription_related_orders'] > 0) {
$subscription_id = absint($_GET['_subscription_related_orders']);
$subscription = wcs_get_subscription($subscription_id);
if (!wcs_is_subscription($subscription)) {
// translators: placeholder is a number
wcs_add_admin_notice(sprintf(__('We can\'t find a subscription with ID #%d. Perhaps it was deleted?', 'woocommerce-subscriptions'), $subscription_id), 'error');
$where .= " AND {$wpdb->posts}.ID = 0";
} else {
self::$found_related_orders = true;
$where .= sprintf(" AND {$wpdb->posts}.ID IN (%s)", implode(',', array_map('absint', array_unique($subscription->get_related_orders('ids')))));
}
}
}
return $where;
}
示例3: save
/**
* Save meta box data
*/
public static function save($post_id, $post)
{
if ('shop_subscription' == $post->post_type && !empty($_POST['woocommerce_meta_nonce']) && wp_verify_nonce($_POST['woocommerce_meta_nonce'], 'woocommerce_save_data')) {
if (isset($_POST['_billing_interval'])) {
update_post_meta($post_id, '_billing_interval', $_POST['_billing_interval']);
}
if (!empty($_POST['_billing_period'])) {
update_post_meta($post_id, '_billing_period', $_POST['_billing_period']);
}
$subscription = wcs_get_subscription($post_id);
$dates = array();
foreach (wcs_get_subscription_date_types() as $date_key => $date_label) {
if ('last_payment' == $date_key) {
continue;
}
$utc_timestamp_key = $date_key . '_timestamp_utc';
// A subscription needs a start date, even if it wasn't set
if (isset($_POST[$utc_timestamp_key])) {
$datetime = $_POST[$utc_timestamp_key];
} elseif ('start' === $date_key) {
$datetime = current_time('timestamp', true);
} else {
// No date to set
continue;
}
$dates[$date_key] = date('Y-m-d H:i:s', $datetime);
}
try {
$subscription->update_dates($dates, 'gmt');
wp_cache_delete($post_id, 'posts');
} catch (Exception $e) {
wcs_add_admin_notice($e->getMessage(), 'error');
}
}
}
示例4: output_rows
/**
* Displays the renewal orders in the Related Orders meta box.
*
* @param object $post A WordPress post
* @since 2.0
*/
public static function output_rows($post)
{
$subscriptions = array();
$orders = array();
// On the subscription page, just show related orders
if (wcs_is_subscription($post->ID)) {
$subscriptions[] = wcs_get_subscription($post->ID);
} elseif (wcs_order_contains_subscription($post->ID, array('parent', 'renewal'))) {
$subscriptions = wcs_get_subscriptions_for_order($post->ID, array('order_type' => array('parent', 'renewal')));
}
// First, display all the subscriptions
foreach ($subscriptions as $subscription) {
$subscription->relationship = __('Subscription', 'woocommerce-subscriptions');
$orders[] = $subscription;
}
//Resubscribed
$initial_subscriptions = array();
if (wcs_is_subscription($post->ID)) {
$initial_subscriptions = wcs_get_subscriptions_for_resubscribe_order($post->ID);
$resubscribed_subscriptions = get_posts(array('meta_key' => '_subscription_resubscribe', 'meta_value' => $post->ID, 'post_type' => 'shop_subscription', 'post_status' => 'any', 'posts_per_page' => -1));
foreach ($resubscribed_subscriptions as $subscription) {
$subscription = wcs_get_subscription($subscription);
$subscription->relationship = _x('Resubscribed Subscription', 'relation to order', 'woocommerce-subscriptions');
$orders[] = $subscription;
}
} else {
if (wcs_order_contains_subscription($post->ID, array('resubscribe'))) {
$initial_subscriptions = wcs_get_subscriptions_for_order($post->ID, array('order_type' => array('resubscribe')));
}
}
foreach ($initial_subscriptions as $subscription) {
$subscription->relationship = _x('Initial Subscription', 'relation to order', 'woocommerce-subscriptions');
$orders[] = $subscription;
}
// Now, if we're on a single subscription or renewal order's page, display the parent orders
if (1 == count($subscriptions)) {
foreach ($subscriptions as $subscription) {
if (false !== $subscription->order) {
$subscription->order->relationship = _x('Parent Order', 'relation to order', 'woocommerce-subscriptions');
$orders[] = $subscription->order;
}
}
}
// Finally, display the renewal orders
foreach ($subscriptions as $subscription) {
foreach ($subscription->get_related_orders('all', 'renewal') as $order) {
$order->relationship = _x('Renewal Order', 'relation to order', 'woocommerce-subscriptions');
$orders[] = $order;
}
}
$orders = apply_filters('woocommerce_subscriptions_admin_related_orders_to_display', $orders, $subscriptions, $post);
foreach ($orders as $order) {
if ($order->id == $post->ID) {
continue;
}
include 'views/html-related-orders-row.php';
}
}
示例5: maybe_remove_or_add_item_to_subscription
/**
* Process the remove or re-add a line item from a subscription request.
*
* @since 2.0
*/
public static function maybe_remove_or_add_item_to_subscription()
{
if (isset($_GET['subscription_id']) && (isset($_GET['remove_item']) || isset($_GET['undo_remove_item'])) && isset($_GET['_wpnonce'])) {
$subscription = wcs_is_subscription($_GET['subscription_id']) ? wcs_get_subscription($_GET['subscription_id']) : false;
$undo_request = isset($_GET['undo_remove_item']) ? true : false;
$item_id = $undo_request ? $_GET['undo_remove_item'] : $_GET['remove_item'];
if (false === $subscription) {
wc_add_notice(sprintf(_x('Subscription #%d does not exist.', 'hash before subscription ID', 'woocommerce-subscriptions'), $_GET['subscription_id']), 'error');
wp_safe_redirect(wc_get_page_permalink('myaccount'));
exit;
}
if (self::validate_remove_items_request($subscription, $item_id, $undo_request)) {
if ($undo_request) {
// handle undo request
$removed_item = WC()->session->get('removed_subscription_items', array());
if (!empty($removed_item[$item_id]) && $subscription->id == $removed_item[$item_id]) {
// restore the item
wc_update_order_item($item_id, array('order_item_type' => 'line_item'));
unset($removed_item[$item_id]);
WC()->session->set('removed_subscription_items', $removed_item);
// restore download permissions for this item
$line_items = $subscription->get_items();
$line_item = $line_items[$item_id];
$_product = $subscription->get_product_from_item($line_item);
$product_id = wcs_get_canonical_product_id($line_item);
if ($_product && $_product->exists() && $_product->is_downloadable()) {
$downloads = $_product->get_files();
foreach (array_keys($downloads) as $download_id) {
wc_downloadable_file_permission($download_id, $product_id, $subscription, $line_item['qty']);
}
}
// translators: 1$: product name, 2$: product id
$subscription->add_order_note(sprintf(_x('Customer added "%1$s" (Product ID: #%2$d) via the My Account page.', 'used in order note', 'woocommerce-subscriptions'), wcs_get_line_item_name($line_item), $product_id));
} else {
wc_add_notice(__('Your request to undo your previous action was unsuccessful.', 'woocommerce-subscriptions'));
}
} else {
// handle remove item requests
WC()->session->set('removed_subscription_items', array($item_id => $subscription->id));
// remove download access for the item
$line_items = $subscription->get_items();
$line_item = $line_items[$item_id];
$product_id = wcs_get_canonical_product_id($line_item);
WCS_Download_Handler::revoke_downloadable_file_permission($product_id, $subscription->id, $subscription->get_user_id());
// remove the line item from subscription but preserve its data in the DB
wc_update_order_item($item_id, array('order_item_type' => 'line_item_removed'));
// translators: 1$: product name, 2$: product id
$subscription->add_order_note(sprintf(_x('Customer removed "%1$s" (Product ID: #%2$d) via the My Account page.', 'used in order note', 'woocommerce-subscriptions'), wcs_get_line_item_name($line_item), $product_id));
// translators: placeholders are 1$: item name, and, 2$: opening and, 3$: closing link tags
wc_add_notice(sprintf(__('You have successfully removed "%1$s" from your subscription. %2$sUndo?%3$s', 'woocommerce-subscriptions'), $line_item['name'], '<a href="' . esc_url(self::get_undo_remove_url($subscription->id, $item_id, $subscription->get_view_order_url())) . '" >', '</a>'));
}
}
$subscription->calculate_totals();
wp_safe_redirect($subscription->get_view_order_url());
exit;
}
}
示例6: wcs_get_subscriptions_for_switch_order
/**
* Get the subscriptions that had an item switch for a given order (if any).
*
* @param int|WC_Order $order_id The post_id of a shop_order post or an instance of a WC_Order object
* @return array Subscription details in post_id => WC_Subscription form.
* @since 2.0
*/
function wcs_get_subscriptions_for_switch_order($order_id)
{
if (is_object($order_id)) {
$order_id = $order_id->id;
}
$subscriptions = array();
$subscription_ids = get_post_meta($order_id, '_subscription_switch', false);
foreach ($subscription_ids as $subscription_id) {
$subscriptions[$subscription_id] = wcs_get_subscription($subscription_id);
}
return $subscriptions;
}
示例7: enqueue_styles_scripts
/**
* Print admin styles/scripts
*/
public function enqueue_styles_scripts()
{
global $post;
// Get admin screen id
$screen = get_current_screen();
if ('shop_subscription' == $screen->id) {
wp_register_script('jstz', plugin_dir_url(WC_Subscriptions::$plugin_file) . '/assets/js/admin/jstz.min.js');
wp_register_script('momentjs', plugin_dir_url(WC_Subscriptions::$plugin_file) . '/assets/js/admin/moment.min.js');
wp_enqueue_script('wcs-admin-meta-boxes-subscription', plugin_dir_url(WC_Subscriptions::$plugin_file) . '/assets/js/admin/meta-boxes-subscription.js', array('wc-admin-meta-boxes', 'jstz', 'momentjs'), WC_VERSION);
wp_localize_script('wcs-admin-meta-boxes-subscription', 'wcs_admin_meta_boxes', apply_filters('woocommerce_subscriptions_admin_meta_boxes_script_parameters', array('i18n_start_date_notice' => __('Please enter a start date in the past.', 'woocommerce-subscriptions'), 'i18n_past_date_notice' => __('Please enter a date at least one hour into the future.', 'woocommerce-subscriptions'), 'i18n_next_payment_start_notice' => __('Please enter a date after the trial end.', 'woocommerce-subscriptions'), 'i18n_next_payment_trial_notice' => __('Please enter a date after the start date.', 'woocommerce-subscriptions'), 'i18n_trial_end_start_notice' => __('Please enter a date after the start date.', 'woocommerce-subscriptions'), 'i18n_trial_end_next_notice' => __('Please enter a date before the next payment.', 'woocommerce-subscriptions'), 'i18n_end_date_notice' => __('Please enter a date after the next payment.', 'woocommerce-subscriptions'), 'process_renewal_action_warning' => __("Are you sure you want to process a renewal?\n\nThis will charge the customer and email them the renewal order (if emails are enabled).", 'woocommerce-subscriptions'), 'payment_method' => wcs_get_subscription($post)->payment_method, 'search_customers_nonce' => wp_create_nonce('search-customers'))));
}
}
示例8: wcs_get_subscription_from_key
/**
* Return an instance of a WC_Subscription object for the given subscription key (if one exists).
*
* @param string $subscription_key A subscription key in the deprecated form created by @see self::get_subscription_key()
* @return WC_Subscription|null The subscription object if it can be found (i.e. an order exists) or null if no order exists for the subscription (i.e. it was manually created).
* @since 2.0
*/
function wcs_get_subscription_from_key($subscription_key)
{
$subscription_id = wcs_get_subscription_id_from_key($subscription_key);
if (null !== $subscription_id && is_numeric($subscription_id)) {
$subscription = wcs_get_subscription($subscription_id);
}
if (!is_object($subscription)) {
// translators: placeholder is either subscription key or a subscription id, or, failing that, empty (e.g. "145_21" or "145")
throw new InvalidArgumentException(sprintf(__('Could not get subscription. Most likely the subscription key does not refer to a subscription. The key was: "%s".', 'woocommerce-subscriptions'), $subscription_key));
}
return $subscription;
}
示例9: get_endpoint_title
/**
* Set the subscription page title when viewing a subscription.
*
* @since 2.0
* @param $title
*/
public function get_endpoint_title($endpoint)
{
global $wp;
switch ($endpoint) {
case 'view-subscription':
$subscription = wcs_get_subscription($wp->query_vars['view-subscription']);
$title = $subscription ? sprintf(_x('Subscription #%s', 'hash before order number', 'woocommerce-subscriptions'), $subscription->get_order_number()) : '';
break;
default:
$title = '';
break;
}
return $title;
}
示例10: cart_needs_payment
/**
* Check whether the cart needs payment even if the order total is $0 because it's a subscription switch request for a subscription using
* PayPal Standard as the subscription.
*
* @param bool $needs_payment The existing flag for whether the cart needs payment or not.
* @param WC_Cart $cart The WooCommerce cart object.
* @return bool
*/
public static function cart_needs_payment($needs_payment, $cart)
{
$cart_switch_items = WC_Subscriptions_Switcher::cart_contains_switches();
if (false === $needs_payment && 0 == $cart->total && false !== $cart_switch_items && 'yes' !== get_option(WC_Subscriptions_Admin::$option_prefix . '_turn_off_automatic_payments', 'no')) {
foreach ($cart_switch_items as $cart_switch_details) {
$subscription = wcs_get_subscription($cart_switch_details['subscription_id']);
if ('paypal' === $subscription->payment_method && !wcs_is_paypal_profile_a(wcs_get_paypal_id($subscription->id), 'billing_agreement')) {
$needs_payment = true;
break;
}
}
}
return $needs_payment;
}
示例11: validate_request
/**
* Checks if the user's current request to change the status of their subscription is valid.
*
* @since 2.0
*/
public static function validate_request($user_id, $subscription, $new_status, $wpnonce = '')
{
$subscription = !is_object($subscription) ? wcs_get_subscription($subscription) : $subscription;
if (!wcs_is_subscription($subscription)) {
WC_Subscriptions::add_notice(__('That subscription does not exist. Please contact us if you need assistance.', 'woocommerce-subscriptions'), 'error');
return false;
} elseif (!empty($wpnonce) && wp_verify_nonce($wpnonce, $subscription->id) === false) {
WC_Subscriptions::add_notice(__('Security error. Please contact us if you need assistance.', 'woocommerce-subscriptions'), 'error');
return false;
} elseif (!user_can($user_id, 'edit_shop_subscription_status', $subscription->id)) {
WC_Subscriptions::add_notice(__('That doesn\'t appear to be one of your subscriptions.', 'woocommerce-subscriptions'), 'error');
return false;
} elseif (!$subscription->can_be_updated_to($new_status)) {
WC_Subscriptions::add_notice(sprintf(__('That subscription can not be changed to %s. Please contact us if you need assistance.', 'woocommerce-subscriptions'), $new_status), 'error');
return false;
}
return true;
}
示例12: trigger_hook
/**
* Display a notice if functions are hooked to the old filter and apply the old filters args
*
* @since 2.0
*/
protected function trigger_hook($old_hook, $new_callback_args)
{
if (0 === strpos($old_hook, 'admin_changed_subscription_to_')) {
// New arg spec: $subscription_id
// Old arg spec: $subscription_key
$subscription = wcs_get_subscription($new_callback_args[0]);
do_action($old_hook, wcs_get_old_subscription_key($subscription));
} elseif (0 === strpos($old_hook, 'scheduled_subscription_payment_')) {
// New arg spec: $amount, $renewal_order
// Old arg spec: $amount, $original_order, $product_id
$subscription = $new_callback_args[0];
$subscriptions = wcs_get_subscriptions_for_renewal_order($new_callback_args[1]);
if (!empty($subscriptions)) {
$subscription = array_pop($subscriptions);
do_action($old_hook, $new_callback_args[0], self::get_order($subscription), self::get_product_id($subscription));
}
} elseif (0 === strpos($old_hook, 'activated_subscription_') || 0 === strpos($old_hook, 'reactivated_subscription_') || 0 === strpos($old_hook, 'subscription_put_on-hold_') || 0 === strpos($old_hook, 'cancelled_subscription_') || 0 === strpos($old_hook, 'subscription_expired_')) {
// New arg spec: $subscription
// Old arg spec: $order, $product_id
$subscription = $new_callback_args[0];
do_action($old_hook, self::get_order($subscription), self::get_product_id($subscription));
} elseif (0 === strpos($old_hook, 'customer_changed_subscription_to_')) {
// New arg spec: $subscription
// Old arg spec: $subscription_key
do_action($old_hook, wcs_get_old_subscription_key($new_callback_args[0]));
} elseif (0 === strpos($old_hook, 'woocommerce_subscriptions_updated_recurring_payment_method_to_')) {
// New arg spec: $subscription, $old_payment_method
// Old arg spec: $order, $subscription_key, $old_payment_method
$subscription = $new_callback_args[0];
$old_payment_method = $new_callback_args[2];
do_action($old_hook, self::get_order($subscription), wcs_get_old_subscription_key($subscription), $old_payment_method);
} elseif (0 === strpos($old_hook, 'woocommerce_subscriptions_updated_recurring_payment_method_from_')) {
// New arg spec: $subscription, $new_payment_method
// Old arg spec: $order, $subscription_key, $new_payment_method
$subscription = $new_callback_args[0];
$new_payment_method = $new_callback_args[1];
do_action($old_hook, self::get_order($subscription), wcs_get_old_subscription_key($subscription), $new_payment_method);
} elseif (0 === strpos($old_hook, 'woocommerce_subscriptions_changed_failing_payment_method_')) {
// New arg spec: $subscription, $renewal_order
// Old arg spec: $original_order, $renewal_order, $subscription_key
$subscription = $new_callback_args[0];
do_action($old_hook, self::get_order($subscription), $new_callback_args[1], wcs_get_old_subscription_key($subscription));
}
}
示例13: orderByItemId
/**
* Get order containing item.
*
* @since 160608 Order item utilities.
*
* @param string|int $item_id Order item ID.
*
* @return \WC_Abstract_Order|null Order on success.
*/
public function orderByItemId($item_id)
{
if (!($item_id = (int) $item_id)) {
return null;
// Not possible.
}
$WpDb = $this->s::wpDb();
// DB instance.
$table = $WpDb->prefix . 'woocommerce_order_items';
$sql = '
SELECT `order_id` FROM `' . esc_sql($table) . '`
WHERE `order_item_id` = %s LIMIT 1';
$sql = $WpDb->prepare($sql, $item_id);
// Prepare.
if (!($order_id = (int) $WpDb->get_var($sql))) {
return null;
// Not possible; can't get order ID.
} elseif (!($post_type = get_post_type($order_id))) {
debug(0, $this->c::issue(vars(), 'Unable to acquire order post type.'));
return null;
// Not possible; can't get post type.
}
switch ($post_type) {
// Based on post type.
case 'shop_subscription':
$subscription_id = $order_id;
// It's a subscription ID.
if ($WC_Subscription = wcs_get_subscription($subscription_id)) {
return $WC_Subscription;
}
return null;
// Not possible.
// Not possible.
case 'shop_order':
default:
// Any other order type.
if ($WC_Order = wc_get_order($order_id)) {
return $WC_Order;
}
return null;
// Not possible.
}
}
示例14: maybe_repair_subscriptions
/**
* Update any subscription that need to be repaired.
*
* @return array The counts of repaired and unrepaired subscriptions
*/
public static function maybe_repair_subscriptions($subscription_ids_to_repair)
{
global $wpdb;
// don't allow data to be half upgraded on a subscription in case of a script timeout or other non-recoverable error
$wpdb->query('START TRANSACTION');
$repaired_count = $unrepaired_count = 0;
foreach ($subscription_ids_to_repair as $subscription_id) {
$subscription = wcs_get_subscription($subscription_id);
if (false !== $subscription && self::maybe_repair_subscription($subscription)) {
WCS_Upgrade_Logger::add(sprintf('For subscription %d: repair completed', $subscription->id));
$repaired_count++;
update_post_meta($subscription_id, '_wcs_repaired_2_0_2', 'true');
} else {
WCS_Upgrade_Logger::add(sprintf('For subscription %d: no repair needed', $subscription->id));
$unrepaired_count++;
update_post_meta($subscription_id, '_wcs_repaired_2_0_2', 'false');
}
}
$wpdb->query('COMMIT');
return array('repaired_count' => $repaired_count, 'unrepaired_count' => $unrepaired_count);
}
示例15: output_rows
/**
* Displays the renewal orders in the Related Orders meta box.
*
* @param object $post A WordPress post
* @since 2.0
*/
public static function output_rows($post)
{
$subscriptions = array();
$orders = array();
// On the subscription page, just show related orders
if (wcs_is_subscription($post->ID)) {
$subscriptions[] = wcs_get_subscription($post->ID);
} elseif (wcs_order_contains_subscription($post->ID, array('parent', 'renewal'))) {
$subscriptions = wcs_get_subscriptions_for_order($post->ID, array('order_type' => array('parent', 'renewal')));
}
// First, display all the subscriptions
foreach ($subscriptions as $subscription) {
$subscription->relationship = _x('Subscription', 'relation to order', 'woocommerce-subscriptions');
$orders[] = $subscription;
}
// Now, if we're on a single subscription or renewal order's page, display the parent orders
if (1 == count($subscriptions)) {
foreach ($subscriptions as $subscription) {
if (false !== $subscription->order) {
$subscription->order->relationship = _x('Parent Order', 'relation to order', 'woocommerce-subscriptions');
$orders[] = $subscription->order;
}
}
}
// Finally, display the renewal orders
foreach ($subscriptions as $subscription) {
foreach ($subscription->get_related_orders('all', 'renewal') as $order) {
$order->relationship = _x('Renewal Order', 'relation to order', 'woocommerce-subscriptions');
$orders[] = $order;
}
}
foreach ($orders as $order) {
if ($order->id == $post->ID) {
continue;
}
include 'views/html-related-orders-row.php';
}
}