Sometimes you want to limit the availability of certain shipping rates. The Premium Shipping plugin has filters that allow you to change the availability of shipping rates according to whatever logic you want.

The example below for example blocks a rate once a certain date has passed – great for holiday-season shipping cut-offs.

// Rate ID 1 should not be available after 20th December 2013
function limit_rate_by_date( $availability, $rate, $rate_id ) {

	// Our function should only apply to rate ID 1
	if ( $rate_id != 1 )
		return $availability;

	// Calculate the date as a UNIX timestamp
	$expiry_time = '2013-11-25T22:36:00+00:00';
	$unix_expiry = strtotime( $expiry_time );

	// If the current time is after the expiry, block the rate
	if ( time() > $unix_expiry )
		return false;

	// Otherwise return the availability of the rate as it would be
	return $availability;

add_filter( 'ses_wpsc_ps_availability', 'limit_rate_by_date', 10, 3 );

This entry was posted in .
Bookmark the permalink.