Use this developer customization when you want USPS Flat Rate boxes to remain available but do not want USPS Shipping Method to use its built-in Flat Rate envelope definitions.
Before you begin
↑ Back to top- This snippet requires USPS Shipping Method.
- Add the code with a site-specific plugin, a child theme, or a code snippet manager.
- Test the change on a staging site before using it on a live store.
Customizations are not covered under our support policy, so this isn’t something we can help implement or troubleshoot on your site.
Remove Flat Rate envelopes
↑ Back to topThe wc_usps_flat_rate_boxes filter receives the built-in Flat Rate package definitions. This snippet removes the domestic and international envelope definitions while leaving the box definitions unchanged.
/**
* Remove USPS Flat Rate envelope definitions while retaining Flat Rate boxes.
*
* @param array<string, array<string, mixed>> $flat_rate_boxes USPS Flat Rate package definitions.
* @return array<string, array<string, mixed>>
*/
function wccom_remove_usps_flat_rate_envelopes( $flat_rate_boxes ) {
$envelope_ids = array(
'd13',
'd16',
'd29',
'd30',
'd38',
'd40',
'd42',
'd44',
'd63',
'i8',
'i13',
'i29',
'i30',
'i63',
);
return array_diff_key( $flat_rate_boxes, array_flip( $envelope_ids ) );
}
add_filter( 'wc_usps_flat_rate_boxes', 'wccom_remove_usps_flat_rate_envelopes' );
This snippet was reviewed against USPS Shipping Method 5.6.1. If USPS adds another Flat Rate envelope definition, add its package ID to the $envelope_ids array.
For the standard package and box-packing settings, see Box Packing in the USPS Shipping Method guide.
Questions and support
↑ Back to topSomething missing from this documentation? Still have questions and need assistance?
- If you have a question about a specific extension or theme you’d like to purchase, contact us to get answers.
- If you already purchased this product and need some assistance, get in touch with a Happiness Engineer via our support page and select this product’s name from the Product dropdown.