ulc_manual_code_length
Filters the maximum length allowed for manually entered coupon codes.
add_filter( 'ulc_manual_code_length', $callback, 10, 1 );
Description
Filters the default length for manually generated coupon codes. Developers can use this hook to customize the string length of codes created through the "Generate Coupon Codes" interface, allowing for longer or shorter codes than the default 30 characters.
Usage
add_filter( 'ulc_manual_code_length', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
/**
* Filter to adjust the default manual code length.
*
* This example demonstrates how to change the default length of manually
* generated codes from 30 characters to 16 characters.
*
* @param int $length The current code length.
* @return int The new code length.
*/
add_filter( 'ulc_manual_code_length', function( $length ) {
// Reduce the default manual code length to 16 characters for quicker testing or specific use cases.
return 16;
}, 10, 1 ); // Priority 10, accepts 1 argument
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/admin/class-generate-codes.php:55
public function __construct() {
self::$chars = apply_filters( 'ulc_code_characters', 'abcdefghjkmnpqrstuvwxyz123456789ABCDEFGHJKLMNPQRSTUVWXYZ' );
self::$manual_code_length = apply_filters( 'ulc_manual_code_length', 30 );
if ( is_admin() ) {
parent::__construct();
self::$courses = LearnDash::get_courses();
self::$groups = LearnDash::get_groups();
}
add_action( 'admin_init', array( $this, 'process_submit' ), 9 );
if ( SharedFunctionality::ulc_filter_has_var( 'msg' ) && 'success' === sanitize_text_field( SharedFunctionality::ulc_filter_input( 'msg' ) ) ) {
add_action( 'admin_notices', array( __CLASS__, 'success_notice' ) );
}
if ( SharedFunctionality::ulc_filter_has_var( 'msg' ) && 'failed' === SharedFunctionality::ulc_filter_input( 'msg' ) ) {
add_action( 'admin_notices', array( __CLASS__, 'failed_notice' ) );
}
}