Skip to content

Instantly share code, notes, and snippets.

@xadapter
Last active March 12, 2020 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save xadapter/a2958646adcc025224dc99c25bf44345 to your computer and use it in GitHub Desktop.
Save xadapter/a2958646adcc025224dc99c25bf44345 to your computer and use it in GitHub Desktop.
Snippet to alter WooCommerce product weight and dimensions dynamically. Supports PluginHive Shipping Plugins: https://www.pluginhive.com/product-category/woocommerce-plugin/woocommerce-shipping/
function filter_get_hook_prefix_weight($this_weight, $instance) {
if (!$this_weight) $this_weight = .6;
return $this_weight;
}
function filter_get_hook_prefix_height($this_height, $instance) {
if (!$this_height) $this_height = 20;
return $this_height;
}
function filter_get_hook_prefix_width($this_width, $instance) {
if (!$this_width) $this_width = 20;
return $this_width;
}
function filter_get_hook_prefix_length($this_length, $instance) {
if (!$this_length) $this_length = 20;
return $this_length;
}
add_filter("woocommerce_product_get_height", 'filter_get_hook_prefix_height', 19, 2);
add_filter("woocommerce_product_get_width", 'filter_get_hook_prefix_width', 19, 2);
add_filter("woocommerce_product_get_length", 'filter_get_hook_prefix_length', 19, 2);
add_filter("woocommerce_product_get_weight", 'filter_get_hook_prefix_weight', 19, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment