Created
March 29, 2022 12:35
-
-
Save bporcelli/d0f8b0ef5de5462910fa31a787fc3fa5 to your computer and use it in GitHub Desktop.
[MarketShip] Set default shipping boxes for Live Rates.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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