Skip to content

Instantly share code, notes, and snippets.

@lucprincen
Created March 3, 2015 12:50
Show Gist options
  • Save lucprincen/18bf4f742b789c39e1b8 to your computer and use it in GitHub Desktop.
Save lucprincen/18bf4f742b789c39e1b8 to your computer and use it in GitHub Desktop.
Woocommerce check weight
add_action( 'woocommerce_add_to_cart', 'check_total_weight' );
function check_total_weight( $itemkey, $product_id, $quantity ){
$product = wc_get_product( $product_id );
$weight = $product->get_weight() * $quantity;
$cart_weight = WC()->cart->cart_contents_weight;
if( $weight + $cart_weight > {TOTAL} ){
wp_redirect( {URL} );
die();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment