ulgm_per_seat_text
Filters the text displayed for per-seat pricing on products, allowing customization of this display text.
add_filter( 'ulgm_per_seat_text', $callback, 10, 3 );
Description
Filters the text displayed for per-seat pricing in WooCommerce. Modify this text to customize how license seat pricing is presented to customers. This hook fires after the default text is retrieved but before it's output.
Usage
add_filter( 'ulgm_per_seat_text', 'your_function_name', 10, 3 );
Parameters
-
$price(mixed) - This parameter contains the formatted price of the product, potentially including currency symbols and formatting.
-
$product(mixed) - This parameter represents the calculated price of the product, which might be modified by the filter.
-
$per_seat_text(mixed) - This parameter is a `WC_Product` object representing the WooCommerce product for which the per-seat text is being generated.
Return Value
The filtered value.
Examples
/**
* Modify the per-seat text displayed for WooCommerce products.
*
* This filter allows developers to customize the text that appears
* after the price to indicate whether the price is per seat or per group.
*
* @param string $price The current price string, potentially with per-seat/group text.
* @param WC_Product $product The WC_Product object for the current product.
* @param string $per_seat_text The default per-seat text, retrieved from settings.
*
* @return string The modified price string.
*/
add_filter( 'ulgm_per_seat_text', 'my_custom_per_seat_text', 10, 3 );
function my_custom_per_seat_text( $price, $product, $per_seat_text ) {
// Retrieve the group text, ensuring it's escaped for security.
$per_group_text = esc_html__( 'Team', 'your-text-domain' );
// Check if the product is configured for a fixed price per group.
// This logic assumes a function 'is_fixed_price_set_for_the_license' exists
// and checks a custom meta or setting on the product.
if ( $product && method_exists( $product, 'get_meta' ) && $product->get_meta( '_is_fixed_group_price' ) === 'yes' ) {
// Replace the default per-seat text with the custom per-group text.
// This regex assumes the price is wrapped in </b></span>.
$price = preg_replace( '/</bdi></span>/', "</bdi> / " . $per_group_text . "</span>", $price );
} else {
// Use the default or custom per-seat text.
$price = preg_replace( '/</bdi></span>/', "</bdi> / " . esc_html( $per_seat_text ) . "</span>", $price );
}
return $price;
}
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.php:1249
public function add_per_seat_text( $price, WC_Product $product ) {
// Value can be saved on settings page
$per_seat_text = get_option( 'ulgm_per_seat_text', 'Seat' );
$per_group_text = esc_html__( 'Group', 'uncanny-learndash-groups' );
//$price = wc_price( SharedFunctions::get_custom_product_price( $product ) );
if ( WoocommerceMinMaxQuantity::is_fixed_price_set_for_the_license( $product->get_id() ) ) {
$price = preg_replace( '/</bdi></span>/', "</bdi> / $per_group_text</span>", $price );
} else {
$price = preg_replace( '/</bdi></span>/', "</bdi> / $per_seat_text</span>", $price );
}
return apply_filters( 'ulgm_per_seat_text', $price, $product, $per_seat_text );
}