Guest User

Untitled

a guest
Jun 22nd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. add_action( 'woocommerce_check_cart_items', 'wceb_check_dates_in_cart', 10, 1 );
  2.  
  3. function wceb_check_dates_in_cart() {
  4.  
  5. $return = true;
  6. $start_date = '';
  7. $end_date = '';
  8.  
  9. $i = 0;
  10. foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
  11.  
  12. if ( isset( $values['_ebs_start'] ) ) {
  13.  
  14. $start = $values['_ebs_start'];
  15. $end = isset( $values['_ebs_end'] ) ? $values['_ebs_end'] : $start;
  16.  
  17. if ( $i === 0 ) {
  18. $start_date = $start;
  19. $end_date = $end;
  20. } else {
  21.  
  22. if ( $start === $start_date && $end === $end_date ) {
  23. $i++;
  24. continue;
  25. } else {
  26. wc_add_notice( __( 'You must select the same dates for all your items.', 'woocommerce' ), 'error' );
  27. return false;
  28. }
  29.  
  30. }
  31.  
  32. $i++;
  33.  
  34. }
  35. }
  36.  
  37. return $return;
  38. }
Add Comment
Please, Sign In to add comment