1. Documentation /
  2. All Products for WooCommerce Subscriptions /
  3. Snippets

Snippets

Use these snippets to customize the appearance and functionality of All Products for WooCommerce Subscriptions.

To use a snippet, download the linked file and activate it as you would with any other plugin. Alternatively, copy the contained code into your child theme’s functions.php file.

Note: We are unable to provide support for customizations under our Support Policy. If you need to customize a snippet, or extend its functionality, seek assistance from a qualified WordPress/WooCommerce Developer. We highly recommend Codeable, or a Certified WooExpert.

Snippets

↑ Back to top

Prevent subscription options from showing up next to cart-items

↑ Back to top

The extension allows customers to switch the subscription plan of individual cart items. If you don’t want to display any subscription plan options next to cart items, use the following snippet:

apfs-hide-cart-item-plan-options.php content:
<?php
/**
 * Plugin Name: All Products for WooCommerce Subscriptions - Hide Cart Item Subscription Options
 * Plugin URI: https://woocommerce.com/products/all-products-for-woocommerce-subscriptions/
 * Description: Use this snippet to hide cart item subscription options.
 * Version: 1.0
 * Author: WooCommerce
 * Author URI: https://woocommerce.com/
 * Developer: Jason Kytros
 *
 *
 * Copyright: © 2021 Automattic.
 * License: GNU General Public License v3.0
 * License URI: http://www.gnu.org/licenses/gpl-3.0.html
 */
 
 add_filter( 'wcsatt_show_cart_item_options', '__return_false' );

View on Github

Prevent coupons from being applied to products on subscription

↑ Back to top

To prevent coupons from being applied to products purchased on subscription, use the following snippet:

View on Github

It is also possible to prevent coupons from being applied to the cart if one or more products are purchased on subscription:

View on Github

Remove subscription details from the catalog price of products with optional subscription plans

↑ Back to top

If a product has optional subscription plans, a suffix is appended to its catalog price to inform customers that it is available on subscription. This suffix can be removed with the following snippet:

View on Github

Hide Subscription plans for specific user roles

↑ Back to top

To hide Subscription plans for specific user roles, use the following snippet:

View on Github

Hide Global Subscription Plans on product pages

↑ Back to top

By default, Global Subscription Plans allow customers to select a subscription plan for products both on their product page and in the cart. To limit the subscription plan selection only in the cart, use the following snippet:

<?php
/**
 * Plugin Name: All Products for WooCommerce Subscriptions - Hide Global Subscription Plans on product pages
 * Plugin URI: https://woocommerce.com/products/all-products-for-woocommerce-subscriptions/
 * Description: Use this plugin to hide Global Subscription Plans on product pages
 * Version: 1.0
 * Author: WooCommerce
 * Author URI: https://woocommerce.com/
 * Developer: Jason Kytros
 *
 * Requires at least: 2.6.0
 * Tested up to: 6.8
 *
 * Copyright: © 2022 Automattic.
 * License: GNU General Public License v3.0
 * License URI: http://www.gnu.org/licenses/gpl-3.0.html
 */

add_filter( 'wcsatt_show_single_product_options', 'hide_global_plans_on_product_pages', 10, 2 );

function hide_global_plans_on_product_pages( $show_plans, $product) {
	$subscription_schemes = WCS_ATT_Product_Schemes::get_subscription_schemes( $product, 'local' );

	if ( empty( $subscription_schemes ) ) {
		$show_plans = false;
	}
	
	return $show_plans;
}
View on Github

Note: Custom Subscription Plans will continue to be visible on product pages.

Hide the Subscription price from Subscription plans

↑ Back to top

By default, a price shows up for every Subscription plan when it is different than the product’s price.

To hide the Subscription price from Subscription plans when the Grouped layout is used, use the following snippet:

View on Github

Display the price of the cheapest plan in the Catalog Price

↑ Back to top

By default, if Subscription plans have a discount then the discount amount is added as a suffix in the product’s Catalog Price.

To display the price of the cheapest plan there instead, use the following snippet:

View on Github

Always calculate Subscription plan discounts based on the Regular product/variation price

↑ Back to top

To make Subscription plan discounts always calculate based on the Regular product/variation price, use the following snippet:

View on Github

This snippet is useful for Variable Products, when the Override Product price option doesn’t have the desired result.

Select a subscription plan as the default payment option for products

↑ Back to top

When a product is offered both one-time and on subscription, the one-time option is selected by default. To select the first subscription plan as the default option, use the following snippet:

get_key();
	return $default_subscription_scheme_key;
}
View on Github

Allow continued access to downloadable files of cancelled Subscriptions

↑ Back to top

Access to downloadable files associated with a subscription will, by default, expire when the subscription is no longer “active” or “pending-cancel” (see this FAQ). This snippet overrides that behavior to allow access as per the Download Expiry setting when the subscription status is “cancelled”.

woocommerce-subscriptions-download-access-after-cancelled.php content:
<?php

/* 
 * Access to downloadable files associated with a subscription will, by default, expire
 * when the subscription is no longer "active" or "pending-cancel". 
 * https://woocommerce.com/document/subscriptions/faq/#section-39
 * This snippet overrides that behavior to allow access as per the Download Expiry settng
 * when the subscription status is "cancelled" 
 */

add_filter ( 'woocommerce_order_is_download_permitted', 'wc_subscription_download_access_after_cancelled', 10, 2 );
function wc_subscription_download_access_after_cancelled( $is_download_permitted, $subscription ) {
  
  if ( $subscription->has_status ( 'cancelled' ) ) {
      return true;
  }
  
  return $is_download_permitted;
  
}

View on Github

Questions & Support

↑ Back to top

Have a question before you buy? Please fill out this pre-sales form.
Already purchased and need assistance? Get in touch with us via the Help Desk!