本文整理汇总了PHP中wcs_is_subscription函数的典型用法代码示例。如果您正苦于以下问题:PHP wcs_is_subscription函数的具体用法?PHP wcs_is_subscription怎么用?PHP wcs_is_subscription使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wcs_is_subscription函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: maybe_revoke_immediate_access
/**
* When adding new downloadable content to a subscription product, check if we don't
* want to automatically add the new downloadable files to the subscription or initial and renewal orders.
*
* @param bool $grant_access
* @param string $download_id
* @param int $product_id
* @param WC_Order $order
* @return bool
* @since 2.0
*/
public static function maybe_revoke_immediate_access($grant_access, $download_id, $product_id, $order)
{
if ('yes' == get_option(WC_Subscriptions_Admin::$option_prefix . '_drip_downloadable_content_on_renewal', 'no') && (wcs_is_subscription($order->id) || wcs_order_contains_subscription($order, 'any'))) {
$grant_access = false;
}
return $grant_access;
}
示例3: 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';
}
}
示例4: 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;
}
}
示例5: wcs_get_subscription
/**
* Main function for returning subscriptions. Wrapper for the wc_get_order() method.
*
* @since 2.0
* @param mixed $the_subscription Post object or post ID of the order.
* @return WC_Subscription
*/
function wcs_get_subscription($the_subscription)
{
if (is_object($the_subscription) && wcs_is_subscription($the_subscription)) {
$the_subscription = $the_subscription->id;
}
$subscription = WC()->order_factory->get_order($the_subscription);
if (!wcs_is_subscription($subscription)) {
$subscription = false;
}
return apply_filters('wcs_get_subscription', $subscription);
}
示例6: process_payment
/**
* Process payment
*
* @param int $order_id
*/
public function process_payment($order_id)
{
if (!$this->order_contains_subscription($order_id) && !wcs_is_subscription($order_id)) {
return parent::process_payment($order_id);
}
$amazon_billing_agreement_id = isset($_POST['amazon_billing_agreement_id']) ? wc_clean($_POST['amazon_billing_agreement_id']) : '';
try {
if (!$amazon_billing_agreement_id) {
throw new Exception(__('An Amazon payment method was not chosen.', 'woocommerce-gateway-amazon-payments-advanced'));
}
$order = new WC_Order($order_id);
$order_total = $order->get_total();
$this->log(__FUNCTION__, "Info: Beginning processing of payment for (subscription) order {$order_id} for the amount of {$order_total} {$order->get_order_currency()}.");
// Set the Billing Agreement Details
$this->set_billing_agreement_details($order, $amazon_billing_agreement_id);
// Confirm the Billing Agreement
$this->confirm_billing_agreement($order_id, $amazon_billing_agreement_id);
// Get the Billing Agreement Details, with FULL address (now that we've confirmed)
$result = $this->get_billing_agreement_details($order_id, $amazon_billing_agreement_id);
// Store the subscription destination
$this->store_subscription_destination($order_id, $result);
// Store Billing Agreement ID on the order and it's subscriptions
$result = update_post_meta($order_id, 'amazon_billing_agreement_id', $amazon_billing_agreement_id);
if ($result) {
$this->log(__FUNCTION__, "Info: Successfully stored billing agreement in meta for order {$order_id}.");
} else {
$this->log(__FUNCTION__, "Error: Failed to store billing agreement in meta for order {$order_id}.");
}
$subscriptions = wcs_get_subscriptions_for_order($order_id);
foreach ($subscriptions as $subscription) {
$result = update_post_meta($subscription->id, 'amazon_billing_agreement_id', $amazon_billing_agreement_id);
if ($result) {
$this->log(__FUNCTION__, "Info: Successfully stored billing agreement in meta for subscription {$subscription->id} (parent order {$order_id}).");
} else {
$this->log(__FUNCTION__, "Error: Failed to store billing agreement in meta for subscription {$subscription->id} (parent order {$order_id}).");
}
}
// Authorize/Capture initial payment, if initial payment required
if ($order_total > 0) {
return $this->authorize_payment($order, $amazon_billing_agreement_id);
}
// No payment needed now, free trial or coupon used - mark order as complete
$order->payment_complete();
$this->log(__FUNCTION__, "Info: Zero-total initial payment for (subscription) order {$order_id}. Payment marked as complete.");
// Remove items from cart
WC()->cart->empty_cart();
// Return thank you page redirect
return array('result' => 'success', 'redirect' => $this->get_return_url($order));
} catch (Exception $e) {
$this->log(__FUNCTION__, "Error: Exception encountered: {$e->getMessage()}");
wc_add_notice(sprintf(__('Error: %s', 'woocommerce-gateway-amazon-payments-advanced'), $e->getMessage()), 'error');
return;
}
}
开发者ID:lilweirdward,项目名称:blofishwordpress,代码行数:59,代码来源:class-wc-gateway-amazon-payments-advanced-subscriptions.php
示例7: create_payload
/**
* Setup payload for subscription webhook delivery.
*
* @since 2.0
*/
public static function create_payload($payload, $resource, $resource_id, $id)
{
if ('subscription' == $resource && empty($payload) && wcs_is_subscription($resource_id)) {
$webhook = new WC_Webhook($id);
$event = $webhook->get_event();
$current_user = get_current_user_id();
wp_set_current_user($webhook->get_user_id());
WC()->api->WC_API_Subscriptions->register_routes(array());
$payload = WC()->api->WC_API_Subscriptions->get_subscription($resource_id);
wp_set_current_user($current_user);
}
return $payload;
}
示例8: 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;
}
示例9: 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';
}
}
示例10: cart_items_loaded_from_session
/**
* Does some housekeeping. Fires after the items have been passed through the get items from session filter. Because
* that filter is not good for removing cart items, we need to work around that by doing it later, in the cart
* loaded from session action.
*
* This checks cart items whether underlying subscriptions / renewal orders they depend exist. If not, they are
* removed from the cart.
*
* @param $cart WC_Cart the one we got from session
*/
public function cart_items_loaded_from_session($cart)
{
$removed_count_subscription = $removed_count_order = 0;
foreach ($cart->cart_contents as $key => $item) {
if (isset($item[$this->cart_item_key]['subscription_id']) && !wcs_is_subscription($item[$this->cart_item_key]['subscription_id'])) {
$cart->remove_cart_item($key);
$removed_count_subscription++;
continue;
}
if (isset($item[$this->cart_item_key]['renewal_order_id']) && !'shop_order' == get_post_type($item[$this->cart_item_key]['renewal_order_id'])) {
$cart->remove_cart_item($key);
$removed_count_order++;
continue;
}
}
if ($removed_count_subscription) {
$error_message = esc_html(_n('We couldn\'t find the original subscription for an item in your cart. The item was removed.', 'We couldn\'t find the original subscriptions for items in your cart. The items were removed.', $removed_count_subscription, 'woocommerce-subscriptions'));
if (!wc_has_notice($error_message, 'notice')) {
wc_add_notice($error_message, 'notice');
}
}
if ($removed_count_order) {
$error_message = esc_html(_n('We couldn\'t find the original renewal order for an item in your cart. The item was removed.', 'We couldn\'t find the original renewal orders for items in your cart. The items were removed.', $removed_count_order, 'woocommerce-subscriptions'));
if (!wc_has_notice($error_message, 'notice')) {
wc_add_notice($error_message, 'notice');
}
}
}
示例11: get_products
/**
* Get original products for a renewal order - so that we can ensure renewal coupons are only applied to those
*
* @param object $subscription subscription
* @return array $product_ids an array of product ids on a subscription renewal order
* @since 2.0.10
*/
protected function get_products($subscription)
{
$product_ids = array();
if (wcs_is_subscription($subscription)) {
foreach ($subscription->get_items() as $item) {
$product_id = $item['variation_id'] ? $item['variation_id'] : $item['product_id'];
if (!empty($product_id)) {
$product_ids[] = $product_id;
}
}
}
return $product_ids;
}
示例12: get_paypal_args
/**
* Override the default PayPal standard args in WooCommerce for subscription purchases when
* automatic payments are enabled and when the recurring order totals is over $0.00 (because
* PayPal doesn't support subscriptions with a $0 recurring total, we need to circumvent it and
* manage it entirely ourselves.)
*
* @since 2.0
*/
public static function get_paypal_args($paypal_args, $order)
{
if (wcs_order_contains_subscription($order, array('parent', 'renewal', 'resubscribe', 'switch')) || wcs_is_subscription($order)) {
if (self::are_reference_transactions_enabled()) {
$paypal_args = self::get_api()->get_paypal_args($paypal_args, $order);
} else {
$paypal_args = WCS_PayPal_Standard_Request::get_paypal_args($paypal_args, $order);
}
}
return $paypal_args;
}
示例13: maybe_zero_total
/**
* Make sure certain totals are set to 0 when the request is to change the payment method without charging anything.
*
* @since 1.4
*/
public static function maybe_zero_total($total, $subscription)
{
global $wp;
if (!empty($_POST['_wcsnonce']) && wp_verify_nonce($_POST['_wcsnonce'], 'wcs_change_payment_method') && isset($_POST['woocommerce_change_payment']) && $subscription->order_key == $_GET['key'] && $subscription->id == absint($_POST['woocommerce_change_payment'])) {
$total = 0;
} elseif (!self::$is_request_to_change_payment && isset($wp->query_vars['order-pay']) && wcs_is_subscription(absint($wp->query_vars['order-pay']))) {
// if the request to pay for the order belongs to a subscription but there's no GET params for changing payment method, the receipt page is being used to collect credit card details so we still need to $0 the total
$total = 0;
}
return $total;
}
示例14: wcs_get_subscriptions_for_renewal_order
/**
* Get the subscription to which a renewal order relates.
*
* @param WC_Order|int $order The WC_Order object or ID of a WC_Order order.
* @since 2.0
*/
function wcs_get_subscriptions_for_renewal_order($order)
{
if (!is_object($order)) {
$order = wc_get_order($order);
}
$subscriptions = array();
$subscription_ids = get_post_meta($order->id, '_subscription_renewal', false);
foreach ($subscription_ids as $subscription_id) {
if (wcs_is_subscription($subscription_id)) {
$subscriptions[$subscription_id] = wcs_get_subscription($subscription_id);
}
}
return apply_filters('wcs_subscriptions_for_renewal_order', $subscriptions, $order);
}
示例15: is_subscription
/**
* Is $order_id a subscription?
* @param int $order_id
* @return boolean
*/
protected function is_subscription($order_id)
{
return function_exists('wcs_order_contains_subscription') && (wcs_order_contains_subscription($order_id) || wcs_is_subscription($order_id) || wcs_order_contains_renewal($order_id));
}