-
-
Save sisaacrussell/79c9e7e4b82212d7e2039cd1f3ac9f4b to your computer and use it in GitHub Desktop.
Set default weight and Dimension for the products in a woocommerce store. Supports ELEX Shipping Plugins https://elextensions.com/product-category/shipping/ Useful for Woocommerce shipping plugins like below: https://www.xadapter.com/product/multiple-carrier-shipping-plugin-woocommerce/ https://www.xadapter.com/product/woocommerce-ups-shipping-p…
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
/** | |
* Snippet to set default weight and Dimension if it's not set for any product. | |
* Created at : 14 May 2018 | |
* Updated at : 16 May 2018 | |
* Xadapter Plugins : https://www.xadapter.com/shop/ | |
* Gist Link : https://gist.github.com/xadapter/4fb8dbfc6c025630558e43488775eb7d | |
*/ | |
// To set Default Length | |
add_filter( 'woocommerce_product_get_length', 'xa_product_default_length' ); | |
add_filter( 'woocommerce_product_variation_get_length', 'xa_product_default_length' ); // For variable product variations | |
if( ! function_exists('xa_product_default_length') ) { | |
function xa_product_default_length( $length) { | |
$default_length = 10; // Provide default Length | |
if( empty($length) ) { | |
return $default_length; | |
} | |
else { | |
return $length; | |
} | |
} | |
} | |
// To set Default Width | |
add_filter( 'woocommerce_product_get_width', 'xa_product_default_width'); | |
add_filter( 'woocommerce_product_variation_get_width', 'xa_product_default_width' ); // For variable product variations | |
if( ! function_exists('xa_product_default_width') ) { | |
function xa_product_default_width( $width) { | |
$default_width = 11; // Provide default Width | |
if( empty($width) ) { | |
return $default_width; | |
} | |
else { | |
return $width; | |
} | |
} | |
} | |
// To set Default Height | |
add_filter( 'woocommerce_product_get_height', 'xa_product_default_height'); | |
add_filter( 'woocommerce_product_variation_get_height', 'xa_product_default_height' ); // For variable product variations | |
if( ! function_exists('xa_product_default_height')) { | |
function xa_product_default_height( $height) { | |
$default_height = 12; // Provide default Height | |
if( empty($height) ) { | |
return $default_height; | |
} | |
else { | |
return $height; | |
} | |
} | |
} | |
// To set Default Weight | |
add_filter( 'woocommerce_product_get_weight', 'xa_product_default_weight' ); | |
add_filter( 'woocommerce_product_variation_get_weight', 'xa_product_default_weight' ); // For variable product variations | |
if( ! function_exists('xa_product_default_weight') ) { | |
function xa_product_default_weight( $weight) { | |
$default_weight = 13; // Provide default Weight | |
if( empty($weight) ) { | |
return $default_weight; | |
} | |
else { | |
return $weight; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment