Filter Uncanny Redemption Codes

ulc_automator_product_limit_issue_max_count

Filters the maximum number of products that can be in a single automator product limit issue.

add_filter( 'ulc_automator_product_limit_issue_max_count', $callback, 10, 1 );

Description

Filters the maximum number of products allowed in an automator. This is useful for adjusting the product limit for specific automator configurations, potentially for performance optimization or custom pricing scenarios. Modifying this value directly impacts the automator's product capacity.


Usage

add_filter( 'ulc_automator_product_limit_issue_max_count', 'your_function_name', 10, 1 );

Parameters

$this (mixed)
This parameter represents the current maximum product count allowed for the automation.

Return Value

The filtered value.


Examples

/**
 * Example of how to use the ulc_automator_product_limit_issue_max_count filter.
 *
 * This filter allows you to modify the maximum number of issues allowed for a product
 * within the Uncanny Automator integration.
 *
 * In this example, we'll check if the product is a specific type (e.g., 'simple')
 * and conditionally adjust the max count. If the product is of type 'simple',
 * we'll allow a higher limit; otherwise, we'll revert to a default or lower limit.
 *
 * @param  mixed  $max_count  The current maximum issue count. Defaults to true (meaning no limit initially).
 * @param  mixed  $this       The instance of the current class (likely Woo_Automator_Codes).
 *
 * @return int The modified maximum issue count for the product.
 */
add_filter( 'ulc_automator_product_limit_issue_max_count', function( $max_count, $this_obj ) {

	// Get the current product ID from the GET parameters.
	$product_id = isset( $_GET['post'] ) ? absint( $_GET['post'] ) : 0;

	if ( $product_id ) {
		// Fetch the product object to check its type.
		$product = wc_get_product( $product_id );

		if ( $product ) {
			// Check if the product is a 'simple' product.
			if ( 'simple' === $product->get_type() ) {
				// For simple products, allow a higher limit, e.g., 10.
				return 10;
			} else {
				// For other product types, enforce a stricter limit, e.g., 3.
				return 3;
			}
		}
	}

	// If we couldn't determine the product or its type, return the original value.
	// In the source code, 'true' likely signifies that the filter should proceed
	// with the default logic if not explicitly overridden.
	return $max_count;

}, 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/integrations/woocommerce/class-woo-automator-codes.php:365
src/classes/integrations/woocommerce/class-woo-automator-codes.php:371

public function add_advanced_pricing() {
		?>
		<div class='options_group show_if_<?php echo $this->product_type; ?>'>
			<?php

			global $wpdb;
			$tbl_groups = $wpdb->prefix . Config::$tbl_groups;
			if ( SharedFunctionality::ulc_filter_has_var( 'post' ) && SharedFunctionality::ulc_filter_has_var( 'action' ) && 'edit' === SharedFunctionality::ulc_filter_input( 'action' ) ) {
				if ( true === apply_filters( 'ulc_automator_product_limit_issue_max_count', true, $this ) ) {
					$sql = $wpdb->prepare( "SELECT * FROM $tbl_groups WHERE code_for=%s AND issue_max_count=%d AND (product_id=%d OR product_id=%d) ORDER BY `name` ASC", 'automator', 1, 0, SharedFunctionality::ulc_filter_input( 'post', INPUT_GET, FILTER_SANITIZE_NUMBER_INT ) );
				} else {
					$sql = $wpdb->prepare( "SELECT * FROM $tbl_groups WHERE code_for=%s AND (product_id=%d OR product_id=%d) ORDER BY `name` ASC", 'automator', 0, SharedFunctionality::ulc_filter_input( 'post', INPUT_GET, FILTER_SANITIZE_NUMBER_INT ) );
				}
			} else {
				if ( true === apply_filters( 'ulc_automator_product_limit_issue_max_count', true, $this ) ) {
					$sql = $wpdb->prepare( "SELECT * FROM $tbl_groups WHERE code_for=%s AND issue_max_count=%d AND product_id=%d ORDER BY `name` ASC", 'automator', 1, 0 );
				} else {
					$sql = $wpdb->prepare( "SELECT * FROM $tbl_groups WHERE code_for=%s AND product_id=%d ORDER BY `name` ASC", 'automator', 0 );
				}
			}
			$batches = $wpdb->get_results( $sql );
			$options = array();
			if ( $batches ) {
				foreach ( $batches as $batch ) {
					$options[ (string) $batch->ID ] = ( empty( $batch->name ) ) ? 'ID: ' . $batch->ID : $batch->name;
				}
			}

			woocommerce_wp_select(
				array(
					'label'   => esc_html__( 'Code batch:', 'uncanny-learndash-codes' ),
					'id'      => 'codes_group_name',
					'options' => $options,
				)
			);

			?>
			<p id="codes_group_error" style="text-align: center;border: 1px orange solid;display: none">
				<i></i>
			</p>
			<?php

			woocommerce_wp_text_input(
				array(
					'id'                => 'codes_group_total',
					'label'             => esc_html__( 'Total codes:', 'uncanny-learndash-codes' ),
					'value'             => '',
					'style'             => '',
					'custom_attributes' => array(
						'disabled' => 'disabled',
					),
				)
			);

			woocommerce_wp_text_input(
				array(
					'id'                => 'codes_group_available',
					'label'             => esc_html__( 'Available codes:', 'uncanny-learndash-codes' ),
					'value'             => '',
					'style'             => '',
					'custom_attributes' => array(
						'disabled' => 'disabled',
					),
				)
			);

			?>
			<button id="codes_group_edit" type="button" style="margin: 5px 0 20px 10px;"
					data-group="0"
					data-href="<?php echo admin_url( 'admin.php?page=uncanny-learndash-codes-create&edit=true&group_id=' ); ?>"
					class="uncannyowl-btn uncannyowl-btn--primary"><?php echo esc_html__( 'Edit Code Batch', 'uncanny-learndash-codes' ); ?>
			</button>

		</div>

		<?php
	}

Scroll to Top