Advertisement
mbcreation

Mandatory house number in address

Apr 29th, 2014
486
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.03 KB | None | 0 0
  1. add_action('woocommerce_checkout_process', 'custom_validation_process');
  2.  
  3. function custom_validation_process()
  4. {
  5.     global $woocommerce;
  6.  
  7.     if(isset($_POST['billing_address_1']) and $_POST['billing_address_1'] != '')
  8.     {
  9.         if (!preg_match('/([0-9]+)/Uis', $_POST['billing_address_1']))
  10.         {
  11.             if(function_exists('wc_add_notice'))
  12.                 wc_add_notice( __('You must enter your house number for the billing address'), 'error' );
  13.             else
  14.                 $woocommerce->add_error( __('You must enter your house number for the billing address') );
  15.         }
  16.     }
  17.    
  18.     if(isset($_POST['ship_to_different_address']))
  19.     {
  20.         if(isset($_POST['shipping_address_1']) and $_POST['shipping_address_1'] != '')
  21.         {
  22.             if (!preg_match('/([0-9]+)/Uis', $_POST['shipping_address_1']))
  23.             {
  24.                 if(function_exists('wc_add_notice'))
  25.                     wc_add_notice( __('You must enter your house number for the shipping address'), 'error' );
  26.                 else
  27.                     $woocommerce->add_error( __('You must enter your house number for the shipping address') );
  28.             }
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement