Advertisement
sunlight76

give field validation

Nov 3rd, 2016
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.84 KB | None | 0 0
  1. /**
  2.  * Validate Custom Field
  3.  *
  4.  * @description check for errors without custom fields
  5.  *
  6.  * @param $valid_data
  7.  * @param $data
  8.  */
  9. function give_myprefix_validate_custom_fields( $valid_data, $data ) {
  10.  
  11.     //Check that we're validating the proper form
  12.     //Remove if this is a global field
  13.     if ( $data['give-form-id'] !== '4855' ) {
  14.         return;
  15.     }
  16.  
  17.     //Check for a referral data
  18.     if ( empty( $data['give_items'] ) ) {
  19.         give_set_error( 'give_items', __( 'Per cortesia indica il numero di panettoni per i quali stai facendo la donazione.', 'give' ) );
  20.     }
  21.    
  22.     if ($data[give-amount] > ($data['give_items']*10)){
  23.         give_set_error( 'give_amount', __( 'Ricorda che la donazione massima per un singolo panettone รจ di 10 euro.', 'give' ) );
  24.         }
  25.    
  26.    
  27. }
  28.  
  29. add_action( 'give_checkout_error_checks', 'give_myprefix_validate_custom_fields', 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement