Advertisement
lorro

WooCommerce - Show custom message in cart totals

Jan 9th, 2022
921
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.10 KB | None | 0 0
  1. <?php
  2.   // WooCommerce - Show custom message in cart totals
  3.   add_action( 'woocommerce_cart_totals_after_shipping', 'custom_cutting_message', 10 );
  4.   function custom_cutting_message() {
  5.     $cart = WC()->cart;
  6.     $subtotal = $cart->get_subtotal();
  7.     if( $subtotal > 450 ) {
  8.       return;
  9.     }
  10.     // loop over $cart items
  11.     $includes_delivery_roll_cutting_class = false;
  12.     foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
  13.       $product = $cart_item['data'];
  14.       $shipping_class = $cart_item['data']->get_shipping_class(); // product shipping class slug
  15.       if( 'delivery-roll-cutting' == $shipping_class ) {
  16.         $includes_delivery_roll_cutting_class = true;
  17.         break;
  18.       }      
  19.     }
  20.     if( $includes_delivery_roll_cutting_class ) {
  21.       print '<tr><th colspan="2" class="shipping_message">This includes cutting the roll.<br>Spend over £450 for free roll cutting and delivery.</th></tr>'.PHP_EOL;
  22.     } else {
  23.       print '<tr><th colspan="2" class="shipping_message">Spend over £450 for free delivery.</th></tr>'.PHP_EOL;
  24.     }
  25.   } // end function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement