Top WooCommerce & WordPress Plugins › Forums › Maximum Products per User for WooCommerce › Is it possible to use different time ranges for different products?
- Support forum for the Maximum Products per User for WooCommerce.
- This topic has 3 replies, 2 voices, and was last updated 3 years, 8 months ago by
Tom Anbinder.
Viewing 4 posts - 1 through 4 (of 4 total)
- AuthorPosts
-
March 31, 2020 at 10:35 am #100367
Giacomo Papasidero
ParticipantHi Tom,
i need to use different time range for different product. It’s possible?April 1, 2020 at 12:30 am #100368Hi 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 ID100
: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.
April 1, 2020 at 4:43 am #100369Giacomo Papasidero
ParticipantThanks.
And if i nee to set more than 1 custom code? How i need to change it?April 1, 2020 at 1:22 pm #100370Hi 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 ); }
- AuthorPosts
Viewing 4 posts - 1 through 4 (of 4 total)
- You must be logged in to reply to this topic.