/** * Create a renewal order to record a scheduled subscription payment. * * This method simply creates an order with the same post meta, order items and order item meta as the subscription * passed to it. * * @param int | WC_Subscription $subscription Post ID of a 'shop_subscription' post, or instance of a WC_Subscription object * @return WC_Subscription * @since 2.0 */ function wcs_create_renewal_order($subscription) { $renewal_order = wcs_create_order_from_subscription($subscription, 'renewal_order'); if (is_wp_error($renewal_order)) { return new WP_Error('renewal-order-error', $renewal_order->get_error_message()); } update_post_meta($renewal_order->id, '_subscription_renewal', $subscription->id); return apply_filters('wcs_renewal_order_created', $renewal_order, $subscription); }
/** * Create a resubscribe order to record a customer resubscribing to an expired or cancelled subscription. * * This method is a wrapper for @see wcs_create_order() which creates an order with the same post meta, order * items and order item meta as the subscription passed to it. No trial periods or sign up fees are applied * to resubscribe orders. * * @param int | WC_Subscription $subscription Post ID of a 'shop_subscription' post, or instance of a WC_Subscription object * @return WC_Subscription * @since 2.0 */ function wcs_create_resubscribe_order($subscription) { $resubscribe_order = wcs_create_order_from_subscription($subscription, 'resubscribe_order'); if (is_wp_error($resubscribe_order)) { return new WP_Error('resubscribe-order-error', $renewal_order->get_error_message()); } // Keep a record of the original subscription's ID on the new order update_post_meta($resubscribe_order->id, '_subscription_resubscribe', $subscription->id, true); do_action('wcs_resubscribe_order_created', $resubscribe_order, $subscription); return $resubscribe_order; }