ulgm_license_is_reviews_allowed
Filters whether reviews are allowed for a given product during license activation.
add_filter( 'ulgm_license_is_reviews_allowed', $callback, 10, 1 );
Description
Allows modification of whether reviews are permitted for a license product. Developers can return `true` to enable reviews or `false` to disable them. This filter fires before the license product is created, providing an opportunity to control review visibility based on product or other conditions.
Usage
add_filter( 'ulgm_license_is_reviews_allowed', 'your_function_name', 10, 1 );
Parameters
-
$product(mixed) - This parameter is a boolean value that determines whether reviews are allowed for the product, with `false` indicating that reviews are not allowed.
Return Value
The filtered value.
Examples
/**
* Example of filtering the ulgm_license_is_reviews_allowed hook.
* This example disables reviews for all license products.
*
* @param bool $allow_reviews Whether reviews are allowed (default is false).
* @param WC_Product $product The WC_Product object.
* @return bool Returns false to disallow reviews.
*/
add_filter( 'ulgm_license_is_reviews_allowed', function( $allow_reviews, $product ) {
// For this specific plugin's license product type, we might want to disable reviews.
// You can add conditional logic here based on the $product object if needed.
// For example: if ( $product->get_type() === 'your_custom_license_type' ) { ... }
// Explicitly return false to disallow reviews for this hook.
return false;
}, 10, 2 );
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-buy-courses.php:342
public static function create_license_product( $args ) {
// Get an empty instance of the product object (defining it's type)
$product = new WC_Product_License();
if ( ! $product ) {
return false;
}
// Product name (Title) and slug
$product->set_name( $args['post_title'] ); // Name (title).
// Status ('publish', 'pending', 'draft' or 'trash')
$product->set_status( isset( $args['post_status'] ) ? $args['post_status'] : 'publish' );
// Visibility ('hidden', 'visible', 'search' or 'catalog')
$product->set_catalog_visibility( 'hidden' );
// Featured (boolean)
$product->set_featured( isset( $args['featured'] ) ? $args['featured'] : false );
// Virtual (boolean)
$product->set_virtual( apply_filters( 'ulgm_license_is_virtual', true, $product ) );
// Downloadable (boolean)
$product->set_downloadable( apply_filters( 'ulgm_license_is_downloadable', false, $product ) );
// Sold Individually
$product->set_sold_individually( apply_filters( 'ulgm_license_is_sold_individually', false, $product ) );
// Reviews
$product->set_reviews_allowed( apply_filters( 'ulgm_license_is_reviews_allowed', false, $product ) );
// Taxes
if ( get_option( 'woocommerce_calc_taxes' ) === 'yes' ) {
$product->set_tax_status( isset( $args['tax_status'] ) ? $args['tax_status'] : 'taxable' );
$product->set_tax_class( isset( $args['tax_class'] ) ? $args['tax_class'] : '' );
}
// Attributes et default attributes
if ( isset( $args['attributes'] ) ) {
$product->set_attributes( self::wc_prepare_product_attributes( apply_filters( 'ulgm_license_attributes', $args['attributes'], $product ) ) );
}
if ( isset( $args['default_attributes'] ) ) {
$product->set_default_attributes( apply_filters( 'ulgm_license_default_attributes', $args['default_attributes'], $product ) );
} // Needs a special formatting
// Product categories and Tags
if ( isset( $args['category_ids'] ) ) {
$product->set_category_ids( apply_filters( 'ulgm_license_category_ids', array( $args['category_ids'] ), $product ) );
}
if ( isset( $args['tag_ids'] ) ) {
$product->set_tag_ids( apply_filters( 'ulgm_license_tag_ids', array( $args['tag_ids'] ), $product ) );
}
if ( 'yes' === get_option( 'woocommerce_calc_taxes' ) ) {
$tax_status = get_option( 'ulgm_group_license_tax_status', '' );
$tax_class = get_option( 'ulgm_group_license_tax_class', '' );
if ( ! empty( $tax_class ) ) {
$product->set_tax_class( $tax_class );
}
if ( ! empty( $tax_status ) ) {
$product->set_tax_status( $tax_status );
}
}
## --- SAVE PRODUCT --- ##
$product->save();
//Set price
$get_price = SharedFunctions::get_custom_product_price( $product, true );
$product->set_price( $get_price );
$product->set_regular_price( $get_price );
return $product;
}