uo_create_new_group_price_type
Filters the price type for newly created groups, allowing modification before it's set.
add_filter( 'uo_create_new_group_price_type', $callback, 10, 1 );
Description
Fires after a new manual group is created to determine its price type. Developers can filter the price type, defaulting to 'closed', to implement custom pricing logic or integrations. This allows dynamic price type assignment based on group ID or other conditions.
Usage
add_filter( 'uo_create_new_group_price_type', 'your_function_name', 10, 1 );
Parameters
-
$group_id(mixed) - This parameter is the default price type of the group, which can be filtered.
Return Value
The filtered value.
Examples
<?php
/**
* Example: Change the default price type for newly created manual groups.
*
* This filter allows developers to dynamically set the price type for a new group
* based on certain conditions. For instance, you might want to make all manually
* created groups 'free' by default, or perhaps 'paid' if the group belongs to
* a specific category.
*
* @param string $price_type The current price type ('closed' by default).
* @param int $group_id The ID of the newly created group.
* @return string The modified price type.
*/
add_filter( 'uo_create_new_group_price_type', function( $price_type, $group_id ) {
// Let's assume we want to make all manually created groups 'free'
// if they are associated with a specific category, for demonstration.
// In a real-world scenario, you'd fetch category information for the group.
// For this example, we'll hardcode a condition. Imagine this group_id
// corresponds to a group that should be free.
$free_group_ids = array( 123, 456 ); // Replace with actual logic to determine if it should be free
if ( in_array( $group_id, $free_group_ids ) ) {
return 'free';
}
// If the conditions aren't met, return the original price type.
return $price_type;
}, 10, 2 ); // 10 is the priority, 2 is the number of arguments accepted by the callback function.
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/helpers/process-manual-group.php:116
)
);
do_action( 'uo_before_manual_group_created', $args, $ld_group_args );
$group_id = wp_insert_post( $ld_group_args );
$price_type = apply_filters( 'uo_create_new_group_price_type', 'closed', $group_id );
update_post_meta( $group_id, '_ulgm_is_custom_group_created', 'yes' );
update_post_meta( $group_id, '_thumbnail_id', $group_image );
update_post_meta( $group_id, '_ld_price_type', $price_type );
update_post_meta(
$group_id,
'_groups',
array(