# tier-pricing-table/7.1.4/src/Integrations/Plugins/WooCommerceSubscriptions.php

Tiered Pricing Table for WooCommerce, version 7.1.4. 112 lines.

- Page: https://pluginprobe.com/plugins/tier-pricing-table/7.1.4/code/src/Integrations/Plugins/WooCommerceSubscriptions.php
- Raw: https://pluginprobe.com/plugins/tier-pricing-table/7.1.4/raw/src/Integrations/Plugins/WooCommerceSubscriptions.php
- Modified: 2026-08-15T22:46:58+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/tier-pricing-table/7.1.4/code/src/Integrations/Plugins/WooCommerceSubscriptions.php#L10-L20`.

```php
<?php namespace TierPricingTable\Integrations\Plugins;

use TierPricingTable\PriceManager;
use WC_Product;

/**
 * Compatibility with WooCommerce Subscriptions "All Products for Subscriptions" (APFS) plans.
 *
 * APFS applies a subscription plan's price/discount to a product purely through view-context
 * `woocommerce_product_get_price` filters (it never writes the price prop). WooCommerce Subscriptions
 * additionally filters non-subscription product prices to 0 during its "recurring totals" pass. Both
 * are `view`-context filters, so reading `get_price('edit')` returns the raw, unmodified price.
 *
 * This integration keeps tiered pricing correct on plan items without changing behaviour for any other
 * store:
 *
 *  - Charging: it recomputes a plan item's tiered price in the "edit" context, so a percentage tier is
 *    based on the raw price rather than the plan-discounted (and, in the recurring pass, zeroed) "view"
 *    price. The plan discount is then applied exactly once — by Subscriptions, when the stored tier
 *    price is read during totals — and the tier no longer collapses to false on renewals.
 *  - Display: it defers a plan item's cart price/subtotal to WooCommerce, which already reflects the
 *    plan discount, instead of the plugin rebuilding it from a fresh (plan-unaware) product instance.
 *
 * Everything is scoped to items actually purchased on a plan and is a no-op unless APFS is active.
 */
class WooCommerceSubscriptions extends PluginIntegrationAbstract {

	public function run() {

		// These hooks are registered unconditionally: run() executes at plugin-include time, before
		// WooCommerce Subscriptions lazily loads its "All Products for Subscriptions" cart API on
		// plugins_loaded. Availability is instead checked inside each callback (isSubscriptionPlanItem),
		// which runs at cart-calculation time, so the callbacks are safe no-ops when APFS is absent.

		// Charging: recompute plan items in the "edit" context (raw price base). Runs even when the
		// incoming price is false — during the recurring pass getTierPrice() returns false because the
		// product's "view" price has been filtered to 0.
		add_filter( 'tiered_pricing_table/cart/product_cart_price',
			function ( $price, $cartItem, $cartItemKey, $totalQuantity ) {

				if ( ! $this->isSubscriptionPlanItem( $cartItem ) ) {
					return $price;
				}

				return PriceManager::getPriceByRules( $totalQuantity, $cartItem['data']->get_id(), 'edit', 'cart',
					false );
			}, 10, 4 );

		// Display: defer the subtotal column to WooCommerce for plan items so it matches the charge.
		add_filter( 'tiered_pricing_table/cart/recalculate_cart_item_subtotal',
			function ( $state, $cartItem ) {
				return $this->isSubscriptionPlanItem( $cartItem ) ? false : $state;
			}, 10, 2 );

		// Display: defer the price column to WooCommerce for plan items.
		add_filter( 'tiered_pricing_table/cart/need_price_recalculation/item',
			function ( $state, $cartItem ) {
				return $this->isSubscriptionPlanItem( $cartItem ) ? false : $state;
			}, 10, 2 );
	}

	/**
	 * Whether a cart item is currently purchased on a subscription plan (APFS).
	 *
	 * Reads the scheme stored on the cart item itself, which survives the cloned recurring cart, rather
	 * than the product object's runtime state.
	 *
	 * @param  array  $cartItem
	 *
	 * @return bool
	 */
	protected function isSubscriptionPlanItem( $cartItem ): bool {

		if ( ! class_exists( '\WCS_ATT_Cart' ) ) {
			return false;
		}

		if ( empty( $cartItem['data'] ) || ! ( $cartItem['data'] instanceof WC_Product ) ) {
			return false;
		}

		$scheme = \WCS_ATT_Cart::get_subscription_scheme( $cartItem );

		// A non-empty, non-'0' scheme key means the item is on a plan; '0'/null means a one-time purchase.
		return ! empty( $scheme ) && '0' !== (string) $scheme;
	}

	public function getTitle(): string {
		return 'WooCommerce Subscriptions';
	}

	public function getDescription(): string {
		return __( 'Apply tiered pricing correctly to products purchased on a WooCommerce Subscriptions plan, in both the initial and recurring totals.', 'tier-pricing-table' );
	}

	public function getSlug(): string {
		return 'woocommerce-subscriptions';
	}

	public function getAuthorURL(): string {
		return 'https://woocommerce.com/products/woocommerce-subscriptions/';
	}

	public function getIconURL(): string {
		return $this->getContainer()->getFileManager()->locateAsset( 'admin/integrations/woocommerce-develop.jpeg' );
	}

	public function getIntegrationCategory(): string {
		return 'custom_product_types';
	}
}

```
