How to create a search filter for shipments?

How to create a search filter for shipments?

custom-filter

Note: “wpcargo_receiver_name” is from the shipment meta key. Make sure that the field name exist in your shipment fields.

Copy the HTML code above the [ wpcargo_account ] shortcode.



<form action="" method="post">
<input type="hidden" name="custom_filter" value="my-custom-filter"/>
<label form="wpcargo_receiver_name">Search Receiver: <input type="text" id="wpcargo_receiver_name" name="wpcargo_receiver_name"/></label>
<input type="submit" name="submit" value="Search" />
</form>


Copy and paste following codes on your child theme’s functions.php file.

add_filter('wpcargo_account_query', 'wpcargo_account_query_callback', 10, 1);
function wpcargo_account_query_callback( $query ){
	// Check if custom_filter is submitted
	if( isset( $_POST['custom_filter'] ) && $_POST['custom_filter'] == 'my-custom-filter' ){
		$query['meta_query'][] = array(
			'key' => 'wpcargo_receiver_name', // shipment metakey to filter
			'value' => $_POST['wpcargo_receiver_name'] // shipment value for the custom filter form
		);
		// Additional Query for multiple filters
		$query['meta_query'][] = array(
			'key' => 'metakey_1', // shipment metakey to filter
			'value' => $_POST['metakey_1'] // shipment value for the custom filter form
		);
		$query['meta_query'][] = array(
			'key' => 'metakey_2', // shipment metakey to filter
			'value' => $_POST['metakey_2'] // shipment value for the custom filter form
		);
	}
	return $query;
}
0
    0
    Your Cart
    Your cart is emptyReturn to Shop