Skip to content

Instantly share code, notes, and snippets.

@bporcelli
Created March 29, 2022 12:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bporcelli/d0f8b0ef5de5462910fa31a787fc3fa5 to your computer and use it in GitHub Desktop.
Save bporcelli/d0f8b0ef5de5462910fa31a787fc3fa5 to your computer and use it in GitHub Desktop.
[MarketShip] Set default shipping boxes for Live Rates.
<?php
/**
* Filters the default value for the `shippo_boxes` user meta key.
*
* @param mixed $value Meta value.
* @param int $user_id User ID.
* @param string $meta_key Meta key.
* @param bool $single Whether to return a single value.
*
* @return array|string
*/
function marketship_filter_default_shippo_boxes( $value, $user_id, $meta_key, $single ) {
if ( 'shippo_boxes' !== $meta_key ) {
return $value;
}
$default_boxes = array(
array (
'name' => 'Default Box',
'template' => 'custom', // Should always be 'custom'.
'length' => '4', // Dimensions are always in store dimension units.
'width' => '4',
'height' => '4',
'weight' => '4', // Weight of empty box.
'weight_unit' => 'oz', // Can be 'g', 'oz', 'lb', or 'kg'.
'weight_limit' => '240', // Max box weight.
'weight_limit_unit' => 'oz',
),
);
return $single ? $default_boxes : array( $default_boxes );
}
add_filter( 'default_user_metadata', 'marketship_filter_default_shippo_boxes', 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment