Preorder

Customisations WPPizza Preorder

Highlighting preorders for days after today in *emails* sent (for print templates, simply use css declarations)

Your email template(s) selected MUST be set to “Html” for this to make any difference set conditionals as required

@param: array
@param: array
@param: str
@param: int
@param: array
@return: array

add_filter( 'wppizza_filter_template_section_customer_styles', 'myprefix_set_email_styles', 10, 5 );
function myprefix_set_email_styles($template_styles, $parameters, $template_type, $template_id, $order){
	/*
	restricting to email templates here 
	*/
	if($template_type == 'emails'){
	
		/*
			set as variable for ease of use 
		*/
		$pluginSlug = 'wppizza_preorder';
	
		/*
			get preorder meta value / timestamp
			this will be something like '2021-02-11 13:45:00' OR 'asap' if nothing was selected
		*/
		$preorder =  wppizza_get_order_meta($order['ordervars']['order_id']['value'], $pluginSlug, true );
		
		/*
			end of day today, based on wordpress timezone settings current time
		*/
		$eod = date('Y-m-d 23:59:59', WPPIZZA_WP_TIME);
		
		/*
			as an example, make the preorder text in the emails red if 
			preorder time is on/after midnight tonight and set fontsize
			set your conditionals as required
		*/
		if($preorder !='asap' && $preorder > $eod ){
			$template_styles[''.$pluginSlug.'-tdall'] = 'color:red;font-size:120%';
		}
		
	}
return $template_styles;
}

Adding additional date format(s) – (see php date format for details)

As with all customisations, use at your own risk. You should test this thoroughly, especially if you want to use textual representations of a part of the date (months, weekdays) or separators other than:

  • “/”(slash)
  • “-“(hyphen)
  • ” “(space)
  • “.”(dots)

Whatever you do, do not use/enable “j F, Y” here as the comma after a textual month will stop the javascript library used from validating the date

@param: array
@return: array

add_filter( 'wppizza_po_filter_dateformat', 'myprefix_add_po_date_format');
function myprefix_add_po_date_format($date_format){
	/* just as example how to do this, this already exists as an option */
	$date_format[] = 'M j, Y';
return $date_format;
}

Alter preorder date/time format *after an order has been made* (I.e in thank you page, emails etc ), regardless of plugin settings

@param: array
@param: array
@param: array
@param: array
@return: array

add_filter('wppizza_filter_order_details_formatted', 'my_custom_details_formatted', 10, 4);
function my_custom_details_formatted($order_formatted, $order_ini, $customer_ini, $order_values){
	
	/*
		preorder plugin slug
	*/
	$plugin_slug = 'wppizza_preorder';
	
	/*
		order id
	*/
	$order_id = $order_values['id'];
	
	/*
		get preorder metavalue timestamp, and reformat from timestamp
		skip if 'asap' 
	*/
	$preorder_meta_value = wppizza_get_order_meta( $order_id, $plugin_slug, true);	
	
	if(!empty($preorder_meta_value) && $preorder_meta_value != 'asap'){
		
		/* 
			set desired format 
		*/
		$custom_format = date('l, d M Y @ H|i|s', strtotime($preorder_meta_value));
		/* 
			alter output of preorder value in emails prints etc
		*/		
		$order_formatted['sections']['customer'][$plugin_slug]['value'] = $custom_format;
		

	}


return $order_formatted;	
}