skip to Main Content

WooCommerce: No PO Boxes

Description

The WooCommerce No PO Boxes Plugin restricts the use of PO Boxes during WooCommerce checkout. It contains a configurable message to display when a PO Box is attempted to be used. Will not limit the use of PO Boxes for carts that only contain digital products.

Screenshots

Extending

Filter: mwnpb_restrict_shipping_method

Example Usage

add_filter( 'mwnpb_restrict_shipping_method', 'mwnpb_restrict_shipping_method_example', 10 );
function mwnpb_restrict_shipping_method_example( $restrict_shipping_method = FALSE ) {

    /*
     * This filter defaults to FALSE. And only fires when a shipping method is NOT
     * restricted from P.O. Box shipping.
     * 
     * This allows you to have exceptions in specific situations to not allow P.O. Box shipping 
     * to a shipping method that would normally allow it.
    */

    // Set $restrict_shipping_method to TRUE to disallow P.O. Boxes
    // (DEFAULT) Set $restrict_shipping_method to FALSE to allow P.O. Boxes

    return $restrict_shipping_method;

}

Filter: mwnpb_allow_pobox

Example Usage

add_filter( 'mwnpb_allow_pobox', 'mwnpb_allow_pobox_example', 10, 3 );
function mwnpb_allow_pobox_example( $allow_po_box = FALSE ) {

    /*
     * This filter defaults to FALSE. It is fired immediately before stopping the
     * checkout process from continuing.
    */

    // Set $allow_po_box to TRUE to allow a P.O. Box ship to address in specific situations
    // (DEFAULT) Set $allow_po_box to FALSE to disallow a P.O. Box from being shipped to.

    return $allow_po_box;

}

Filter: mmwc_restricted_message

Example Usage

add_filter( 'mmwc_restricted_message', 'mmwc_restricted_message_example', 10, 3 );
function mmwc_restricted_message_example( $message, $restricted_string, $field_with_restricted_string ) {

	// use $restricted_string to customize $message based on different conditions. 
	// use $field_with_restricted_string to customize the message based on what field the restriction occurred in

	$message = 'This is the message I want to display now instead of the saved one from the dashboard';

	return $message;

}

Filter: mmwc_restricted_words

Example Usage

add_filter( 'mmwc_restricted_words', 'mmwc_restricted_words_example', 10, 1 );
function mmwc_restricted_words_example( $words ) {

	/*
	 * You'll need to modify this example function since a number of different filtering options are being used.
	 */

	// Remove options by word (has to be exact to what is in `MajeMedia_WC_No_Po_Checkout::restricted_strings()` );
	if ( ( $key = array_search( 'word I do not want to filter', $words ) ) !== FALSE ) {
		unset( $words[ $key ] );
	}

	// Remove strings by array_key from `MajeMedia_WC_No_Po_Checkout::restricted_strings()`
	unset( $words[ 0 ] ); // unsets "po box"

	// Add an additional string
	$words[] = 'my new restricted string';

	// delete all restricted strings from default plugin and define your own
	$words = array( 'my restriction 1', 'my restriction 2' );

	return $words;

}
Back To Top