Un fanático de WooCommerce me preguntó: «¿Cómo niegas la pago si el peso del carrito está por encima de cierto umbral?«.
Bueno, esto es sencillo gracias a una función de núcleo de WooCommerce llamada «CART_CONTENTS_WEight» que le permite obtener el peso total de su carrito, y luego la función «WC_ADD_NOTICE» que muestra un error de notificación.
¡Disfrutar!
Php Snippet: Denegar el procesamiento de pago de WooCommerce si el peso del carrito> umbral
/** n*@snippet Deny Checkout Based on Cart Weight - WooCommerce n*@how-to https://tdestudiodesign.com/tutoriales n*@author Tomás Lucas D´Amario, TD Estudio Design n*@compatible WooCommerce 6 n*@community https://tdestudiodesign.com/club */ add_action( 'woocommerce_after_checkout_validation', 'tddesign_deny_checkout_if_weight' ); function tddesign_deny_checkout_if_weight( $posted ) { $max_weight = 100; if ( WC()->cart->cart_contents_weight > $max_weight ) { $notice = 'Sorry, your cart has exceeded the maximum allowed weight of ' . $max_weight . get_option( 'woocommerce_weight_unit' ); wc_add_notice( $notice, 'error' ); } }