Is it possible to use different time ranges for different products?

Top WooCommerce & WordPress Plugins Forums Maximum Products per User for WooCommerce Is it possible to use different time ranges for different products?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #100367
    Giacomo Papasidero
    Participant

    Hi Tom,
    i need to use different time range for different product. It’s possible?

    #100368
    Tom Anbinder
    Moderator
    Plugin Support

    Hi Giacomo,

    This is possible, however, you would need to add a small PHP snippet to your (child) theme’s functions.php file. For example, to set custom date range (lifetime) for product ID 100:

    add_filter( 'alg_wc_mppu_date_range', 'my_custom_alg_wc_mppu_date_range', 10, 3 );
    function my_custom_alg_wc_mppu_date_range( $date_range, $product_or_term_id, $is_product ) {
        // possible date range values are: 'lifetime', 'this_hour', 'this_day', 'this_week', 'this_month', 'this_year', 'last_hour', 'last_24_hours', 'last_7_days', 'last_30_days', 'last_365_days', 'custom'
        return ( $is_product && 100 == $product_or_term_id ? 'lifetime' : $date_range );
    }
    

    I hope this helps. Please let me know if you have any questions.

    #100369
    Giacomo Papasidero
    Participant

    Thanks.
    And if i nee to set more than 1 custom code? How i need to change it?

    #100370
    Tom Anbinder
    Moderator
    Plugin Support

    Hi Giacomo,

    Do you mean that you want to set different date range for more than one product? If that’s the case, here it is:

    add_filter( 'alg_wc_mppu_date_range', 'my_custom_alg_wc_mppu_date_range', 10, 3 );
    function my_custom_alg_wc_mppu_date_range( $date_range, $product_or_term_id, $is_product ) {
        // possible `$date_range` values are: 'lifetime', 'this_hour', 'this_day', 'this_week', 'this_month', 'this_year', 'last_hour', 'last_24_hours', 'last_7_days', 'last_30_days', 'last_365_days', 'custom'
        $product_date_range = array(
            100 => 'lifetime',
            110 => 'this_year',
            // TODO: here you can add more date range per product values, in "product_id => date_range" format
        );
        return ( $is_product && isset( $product_date_range[ $product_or_term_id ] ) ? $product_date_range[ $product_or_term_id ] : $date_range );
    }
    
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.