ulgm_per_seat_text_subscription
Filters the subscription string for per-seat text displayed on the user's account page.
add_filter( 'ulgm_per_seat_text_subscription', $callback, 10, 3 );
Description
This filter allows modification of the "per seat" text displayed for subscription products in WooCommerce. Developers can alter the subscription string, the product object, or the default per-seat text. It fires after initial subscription string generation but before it's displayed, offering flexibility in how subscription pricing is communicated.
Usage
add_filter( 'ulgm_per_seat_text_subscription', 'your_function_name', 10, 3 );
Parameters
-
$subscription_string(mixed) - This parameter contains the original subscription price string generated by WooCommerce Subscriptions.
-
$product(mixed) - This parameter contains the subscription price string for the product.
-
$per_seat_text(mixed) - This parameter contains the WooCommerce product object for which the subscription text is being generated.
Return Value
The filtered value.
Examples
<?php
/**
* Modify the subscription string to append a custom "per user" text if the product is a subscription and has "per user" pricing enabled.
*
* @param string $subscription_string The original subscription string.
* @param WC_Product $product The WC_Product object.
* @param string $per_seat_text The default "per seat" text.
* @return string The modified subscription string.
*/
add_filter( 'ulgm_per_seat_text_subscription', function( $subscription_string, WC_Product $product, $per_seat_text ) {
// Check if the product is a subscription.
if ( ! class_exists( 'WC_Subscriptions_Product' ) || ! WC_Subscriptions_Product::is_subscription( $product->get_id() ) ) {
return $subscription_string;
}
// Get the license meta field for the product.
$license_meta_field = SharedFunctions::$license_meta_field; // Assuming SharedFunctions is accessible
$courses = get_post_meta( $product->get_id(), $license_meta_field, true );
// If there are courses associated, and it's a "per seat" product.
if ( ! empty( $courses ) ) {
// Get the custom "per seat" text from options, defaulting to 'Seat'.
$custom_per_seat_text = get_option( 'ulgm_per_seat_text', __( 'Seat', 'your-text-domain' ) );
// If the product is a fixed price subscription, change "per seat" to "group".
$fixed_price = get_post_meta( $product->get_id(), 'ulgm_license_fixed_price', true );
if ( 'yes' === $fixed_price ) {
$custom_per_seat_text = __( 'group', 'your-text-domain' );
}
// Append the "per seat" text to the subscription string.
$subscription_string .= " / " . $custom_per_seat_text;
}
return $subscription_string;
}, 10, 3 ); // Priority 10, accepts 3 arguments.
?>
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/classes/woocommerce/woocommerce-license-subscription.php:318
src/classes/woocommerce/woocommerce-license-subscription.php:347
public function subs_price_string( $subscription_string, WC_Product $product ) {
if ( empty( $subscription_string ) ) {
return $subscription_string;
}
if ( ! class_exists( 'WC_Subscriptions_Product' ) || ! WC_Subscriptions_Product::is_subscription( $product->get_id() ) ) {
return $subscription_string;
}
$courses = get_post_meta( $product->get_id(), SharedFunctions::$license_meta_field, true );
$fixed_price = (string) get_post_meta( $product->get_id(), 'ulgm_license_fixed_price', true );
if ( ! empty( $courses ) ) {
$per_seat_text = get_option( 'ulgm_per_seat_text', __( 'Seat', 'uncanny-learndash-groups' ) );
if ( 'yes' === $fixed_price ) {
$per_seat_text = __( 'group', 'uncanny-learndash-groups' );
}
$subscription_string .= " / $per_seat_text";
$subscription_string = apply_filters( 'ulgm_per_seat_text_subscription', $subscription_string, $product, $per_seat_text );
}
return $subscription_string;
}