How do I define two date ranges for two different categories?

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #100530
    Mohsen Talani

    I need to define two date range for two different categories.
    For example, category A has an annual limit and category B has a monthly limit.
    How can I do this?

    WPFactory Plugins
    Plugin Author

    Hi Mohsen,

    Sorry for the delay,

    First, you could setup the default date range that would work for most of your categories, let’s say monthly. And then you could enable Limits > Per product category and edit the limit on the category page.

    Finally, you’d have to use a custom code for the other category with different date range. I’ve created it for you as an example considering the id of the category A as 41

    add_filter( 'alg_wc_mppu_date_to_check', function ( $date_to_check, $date_range, $current_time, $product_or_term_id, $current_user_id, $is_product ) {
    	if ( ! $is_product ) {
    		return $date_to_check;
    	$product_categories_ids = wp_get_post_terms( $product_or_term_id, 'product_cat', array( 'fields' => 'ids' ) );
    	// Yearly for category A (41)
    	if ( in_array( 41, $product_categories_ids ) ) {
    		$date_to_check = ( $current_time - YEAR_IN_SECONDS );
    	return $date_to_check;
    }, 10, 6 );

    Let me know if it helps 😉

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.