• Resolved kiruba92

    (@kiruba92)


    I want to increase the product variation limit in woo commerce.

    In existing woo commerce code, The product variation limit is 100.

    $limit = apply_filters( ‘woocommerce_rest_batch_items_limit’, 100, $this->get_normalized_rest_base() );

    I changed the existing code product variation limit as 100 to 200.

    $limit = apply_filters( ‘woocommerce_rest_batch_items_limit’, 200, $this->get_normalized_rest_base() );

    It works but when I update my woo commerce plugin existing code changes are removed.

    So I want that changes in function.php file. How to do it.

    Base Code

    ( wordpress/plugin/woocommerce/includes/abstract/abstract-wc-rest-controller )

    protected function check_batch_limit( $items ) {
    	$limit = apply_filters( 'woocommerce_rest_batch_items_limit', 100, $this->get_normalized_rest_base() );
    	$total = 0;
    
    	if ( ! empty( $items['create'] ) ) {
    		$total += count( $items['create'] );
    	}
    
    	if ( ! empty( $items['update'] ) ) {
    		$total += count( $items['update'] );
    	}
    
    	if ( ! empty( $items['delete'] ) ) {
    		$total += count( $items['delete'] );
    	}
    
    	if ( $total > $limit ) {
    	/* translators: %s: items limit */
    		return new WP_Error( 'woocommerce_rest_request_entity_too_large', sprintf( __( 'Unable to accept more than %s items for this request.', 'woocommerce' ), $limit ), array( 'status' => 413 ) );
    	}
    
    	return true;
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • I think by adding this:

    add_filter( 'woocommerce_ajax_variation_threshold', 'ww_ajax_variation_threshold', 10, 2 );
    
    function ww_ajax_variation_threshold( $default, $product ) {
    	return 150; // increase this number if needed
    }
    Plugin Support RK a11n

    (@riaanknoetze)

    From what I can see, the reply from @darkallman is close, it’s just that your code seems to be focused on the REST API, which means the filter required is different. You’d need to look into using woocommerce_rest_batch_items_limit instead ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Increase product variation limit in woo commerce’ is closed to new replies.