Artistudio Technical
Subscription.md
The WooCommerce Subscriptions plugin is an extension for WooCommerce (a popular eCommerce platform for WordPress) that enables website owners to offer subscription-based products or services. This plugin allows businesses to create and manage recurring payments, offering products like subscription boxes, memberships, or software access with automatic billing on a weekly, monthly, or yearly basis.
Key Features:
- Recurring Payments: Automates billing for subscription plans on a defined schedule (daily, weekly, monthly, yearly).
- Multiple Billing Schedules: Allows various billing cycles for different products or services.
- Flexible Product Types: Subscriptions can be applied to physical goods, digital products, services, or memberships.
- Customer Management: Customers can manage their subscriptions (like upgrading or canceling) from their WooCommerce account.
- Free Trials & Sign-Up Fees: Option to offer free trials or charge a one-time sign-up fee for new subscribers.
- Integration with Payment Gateways: Supports various payment gateways, allowing for automatic recurring payments via platforms like PayPal, Stripe, and others.
- Renewals & Expirations: Automates subscription renewals and handles expirations efficiently.
- Discounts & Coupons: Allows the application of discounts or coupons to subscription products.
- Pro-Rata Billing: Option for prorating charges when customers upgrade or downgrade their subscription mid-cycle.
This plugin is especially useful for businesses that want to establish a steady revenue stream through recurring billing models.
Options
- Accept Manual Renewals: You can turn on this option if you want the renewals to be done manually, this is usually useful if you develop feature or testing the plugin
Hook
-
woocommerce_checkout_create_subscription
After order is created, WC Subscription will duplicate original order. This hook can be used for update meta data on subscription order.
add_action( 'woocommerce_checkout_create_subscription', array( $this, 'remove_excluded_meta_keys_from_subscription' ), 999, 4 );
public function remove_excluded_meta_keys_from_subscription( $subscription, $posted_data, $order, $cart ) {
// Remove specified meta keys.
foreach ( $this->_excluded_meta_keys as $meta_key ) {
if ( $subscription->meta_exists( $meta_key ) ) {
$subscription->delete_meta_data( $meta_key );
}
}
}
-
wc_subscriptions_renewal_order_data
This hook allows you to append excluded meta keys to the renewal order data before it is saved. It's useful for ensuring that certain meta keys are not carried over to the renewal order.
add_filter( 'wc_subscriptions_renewal_order_data', array( $this, 'include_excluded_meta_keys_for_renewal_order' ), 10, 1 );
public function include_excluded_meta_keys_for_renewal_order( $order_data ) {
// Remove excluded meta keys from the order data if they exist.
foreach ( $this->_excluded_meta_keys as $meta_key ) {
unset( $order_data[ $meta_key ] );
}
return $order_data;
}
-
wcs_renewal_order_created
This hook is triggered after a renewal order is created. It allows for modifications to the renewal order, such as recalculating totals based on the current state of the renewal order.
add_filter( 'wc_subscriptions_renewal_order_data', array( $this, 'include_excluded_meta_keys_for_renewal_order' ), 10, 1 );
public function update_renewal_order_total( $renewal_order, $subscription ) {
// Re-Calculate the totals based on the current state of the renewal order.
$renewal_order->calculate_totals();
$renewal_order->save();
}