Snippets

There are two hooks available that you can use to customize the cart item price and the cart item subtotal on the Cart page. 

Both snippets can be added to the bottom of your functions.php file in your child theme or using the Code Snippets plugin.

In this article

Product price filter

By default, the product price on the Cart page shows the total product price for all periods. 
So, if a pair of sunglasses costs $100, the total product price shows as $100 even though the customer is paying $25 every month for 4 periods.

Example #1: Product price for one period
function my_wpp_cart_item_price($price_html, $cart_item, $cart_item_key, $product_price, $scheme_interval, $scheme_period, $scheme_length, $scheme_sign_up_price){

	// example #1
	// <span class='price-amount'>$XX</span> (price for one period, eg. one month)
	$price_html = wc_price($product_price);

	return $price_html;
}

add_filter('wpp_cart_item_price_html', 'my_wpp_cart_item_price', 10, 8);

Example #2: Product price for all periods
function my_wpp_cart_item_price($price_html, $cart_item, $cart_item_key, $product_price, $scheme_interval, $scheme_period, $scheme_length, $scheme_sign_up_price){

	// example #2
	// or price for all periods:
	$price_html = wc_price($product_price * $scheme_length / $scheme_interval);

	return $price_html;
}

add_filter('wpp_cart_item_price_html', 'my_wpp_cart_item_price', 10, 8);

Example #3: Product price (all periods + sign-up fee)
function my_wpp_cart_item_price($price_html, $cart_item, $cart_item_key, $product_price, $scheme_interval, $scheme_period, $scheme_length, $scheme_sign_up_price){

	// example #3
	// or full price (all periods + sign-up fee):
	$price_html = wc_price($product_price * $scheme_length / $scheme_interval + $scheme_sign_up_price);

	return $price_html;
}

add_filter('wpp_cart_item_price_html', 'my_wpp_cart_item_price', 10, 8);

Note: no screenshot is shown for example #3 as the sunglasses product in this example does not have a sign-up fee.

Subtotal filter

By default, the product subtotal on the Cart page shows the price for one period + sign-up fee. In addition, it shows the price for all periods with the total amount payable over X periods. 

Example #1: Product subtotal for one period

function my_wpp_cart_item_subtotal($subtotal_html, $cart_item, $cart_item_key, $product_price, $scheme_interval, $scheme_period, $scheme_length, $scheme_sign_up_price){

	// example #1
	// we can change it to smh like:
	// <span class='price-amount'>$XX</span> (price for one period, eg. one month)
	$subtotal_html = wc_price($product_price * $cart_item['quantity']);

	return $subtotal_html;
}

Example #2: Product subtotal for all periods

function my_wpp_cart_item_subtotal($subtotal_html, $cart_item, $cart_item_key, $product_price, $scheme_interval, $scheme_period, $scheme_length, $scheme_sign_up_price){

	// example #2
	// or price for all periods:
	$subtotal_html = wc_price($product_price * $cart_item['quantity'] * $scheme_length / $scheme_interval);

	return $subtotal_html;
}

Example #3: Product subtotal (all periods + sign-up fee)

function my_wpp_cart_item_subtotal($subtotal_html, $cart_item, $cart_item_key, $product_price, $scheme_interval, $scheme_period, $scheme_length, $scheme_sign_up_price){

	// example #3
	// or full price (all periods + sign-up fee):
	$subtotal_html = wc_price($product_price * $cart_item['quantity'] * $scheme_length / $scheme_interval + $scheme_sign_up_price * $cart_item['quantity']);

	return $subtotal_html;
}

Note: no screenshot is shown for example #3 as the Sunglasses product in this example does not have a sign-up fee.

Example #4: Product subtotal (all periods + sign-up fee) and a notice about the amount of payments

function my_wpp_cart_item_subtotal($subtotal_html, $cart_item, $cart_item_key, $product_price, $scheme_interval, $scheme_period, $scheme_length, $scheme_sign_up_price){

	// example #4
	// or full price (all periods + sign-up fee)
	// and a notice about the amount of payments (eg. 4 total payments)
	$subtotal_html = wc_price($product_price * $cart_item['quantity'] * $scheme_length / $scheme_interval + $scheme_sign_up_price * $cart_item['quantity']).
		"<div>". sprintf(_n('%s total payment', '%s total payments', $scheme_length / $scheme_interval, 'my-text-domain'), $scheme_length / $scheme_interval) ."</div>";

	return $subtotal_html;
}

add_filter('wpp_cart_item_subtotal_html', 'my_wpp_cart_item_subtotal', 10, 8);

Example #5: Product subtotal for one period and a notice about the amount of payments

function my_wpp_cart_item_subtotal($subtotal_html, $cart_item, $cart_item_key, $product_price, $scheme_interval, $scheme_period, $scheme_length, $scheme_sign_up_price){

	// example #5
	// price for one period
	// and a notice about the amount of payments (eg. 4 monthly payments)
	$subtotal_html = wc_price($product_price * $cart_item['quantity']).
		"<div>". sprintf(_n('%s monthly payment', '%s monthly payments', $scheme_length / $scheme_interval, 'my-text-domain'), $scheme_length / $scheme_interval) ."</div>";

	return $subtotal_html;
}

add_filter('wpp_cart_item_subtotal_html', 'my_wpp_cart_item_subtotal', 10, 8);

Example #6: Product subtotal for one period and a sign-up fee

function my_wpp_cart_item_subtotal($subtotal_html, $cart_item, $cart_item_key, $product_price, $scheme_interval, $scheme_period, $scheme_length, $scheme_sign_up_price){

	// example #6
	// total price today (price for one period + sign-up fee):
	$subtotal_html = wc_price($product_price * $cart_item['quantity'] + $scheme_sign_up_price * $cart_item['quantity']);

	return $subtotal_html;
}

add_filter('wpp_cart_item_subtotal_html', 'my_wpp_cart_item_subtotal', 10, 8);

Note: no screenshot is shown for example #6 as the Sunglasses product in this example does not have a sign-up fee.

By default both filters are applied only on the Cart page.

LearnDash Compatibility

Will a user's access to a course expire after all payment plans are paid? 

A common issue that occurs with LearnDash courses is that, when a user completes all installments on a payment plan, their subscription status is updated from Active to Expired. So, LearnDash then removes access to the course for the user. 

To allow a user to continue to have access to their LearnDash course after making all payments, add the following snippet to your functions.php file in your child theme.

function my_wpp_keep_course_access_on_expired_subscriptions(){ 	
	remove_action('woocommerce_subscription_status_expired', array('Learndash_WooCommerce', 'remove_subscription_course_access')); 
}  

add_action('init', 'my_wpp_keep_course_access_on_expired_subscriptions');

How can I extend more than 24 months financing to 36, 48, 60, 72, and 84 months?

Add the following snippet to your functions.php file or using the Code Snippets plugin:

// Extend Payment Plan lengths for 36 months, 48 months, 60 months, 72 months, 84 months
function wpp_extend_subscription_expiration_options( $subscription_lengths ) {

	$subscription_lengths['month'][36] = wcs_get_subscription_period_strings(36, 'month');

	$subscription_lengths['month'][48] = wcs_get_subscription_period_strings(48, 'month');

	$subscription_lengths['month'][60] = wcs_get_subscription_period_strings(60, 'month');

	$subscription_lengths['month'][72] = wcs_get_subscription_period_strings(72, 'month');

	$subscription_lengths['month'][84] = wcs_get_subscription_period_strings(84, 'month');

	return $subscription_lengths;
}

add_filter('woocommerce_subscription_lengths', 'wpp_extend_subscription_expiration_options');

After adding this snippet you will have the option to extend payment plan length for 36 months, 48 months, 60 months, 72 months, 84 months.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us