Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Add weight limit into cart page for some product category or categories
- add_action( 'woocommerce_check_cart_items', 'cldws_set_weight_requirements');
- function cldws_set_weight_requirements() {
- if( is_cart() || is_checkout() ) {
- global $woocommerce;
- $product_in_cart = false;
- foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) {
- $_product = $values['data'];
- $terms = get_the_terms( $_product->id, 'product_cat' );
- foreach ($terms as $term) {
- $_categoryid = $term->term_id;
- if ( ($_categoryid === 132) || ($_categoryid === 129 ) || ($_categoryid === 135) ) {
- $product_in_cart = true;
- $minimum_weight = 2000;
- $cart_contents_weight = WC()->cart->cart_contents_weight;
- if( $cart_contents_weight < $minimum_weight ) {
- wc_add_notice( sprintf('<strong>The error message. Minimal weight is %s%s.</strong>'
- . '<br />Current weight of order: %s%s',
- $minimum_weight,
- get_option( 'woocommerce_weight_unit' ),
- $cart_contents_weight,
- get_option( 'woocommerce_weight_unit' ),
- get_permalink( wc_get_page_id( 'shop' ) )
- ),
- 'error' );
- } break 2;
- }
- }
- }
- return $product_in_cart;
- }
- }
- if (has_term('mrazene','product_shipping_class',$_product->id)) {
- $product_in_cart = true;
- $minimum_weight = 2000;
- $cart_contents_weight = WC()->cart->cart_contents_weight;
- if( $cart_contents_weight < $minimum_weight ) {
- wc_add_notice( sprintf('<strong>The error message. Minimal weight is %s%s.</strong>'
- . '<br />Current weight: %s%s',
- $minimum_weight,
- get_option( 'woocommerce_weight_unit' ),
- $cart_contents_weight,
- get_option( 'woocommerce_weight_unit' ),
- get_permalink( wc_get_page_id( 'shop' ) )
- ),
- 'error' );
- } break 2;
- $chosen_shipping_rates = WC()->session->get( 'chosen_shipping_methods' );
- if ( ! in_array( 'local_pickup', $chosen_shipping_rates ) ) {
- if (has_term('mrazene','product_shipping_class',$_product->id)) {
- $product_in_cart = true;
- $minimum_weight = 2000;
- $cart_contents_weight = WC()->cart->cart_contents_weight;
- if( $cart_contents_weight < $minimum_weight ) {
- wc_add_notice( sprintf('<strong>The error message. Minimal weight is %s%s.</strong>'
- . '<br />Current weight: %s%s',
- $minimum_weight,
- get_option( 'woocommerce_weight_unit' ),
- $cart_contents_weight,
- get_option( 'woocommerce_weight_unit' ),
- get_permalink( wc_get_page_id( 'shop' ) )
- ),
- 'error' );
- } break 2;
- }
- endif;
Add Comment
Please, Sign In to add comment