add_action('woocommerce_checkout_process', 'my_custom_checkout_field_process'); function my_custom_checkout_field_process() { global $woocommerce; // Check if set, if its not set add an error. This one is only requite for companies if ( ! (preg_match('/^[0-9]{4}$/D', $_POST['billing_postcode'] ))){ wc_add_notice( "The Postcode should contain only 4 digits" ,'error' ); } if( ! (preg_match("/^[a-zA-Z]+$/", $_POST['billing_first_name']))){ wc_add_notice( "The Billing First Name should contain only alphanumeric characters [a-z] and [A-Z]" ,'error' ); } if( ! (preg_match("/^[a-zA-Z]+$/", $_POST['billing_last_name']))){ wc_add_notice( "The Billing Last Name should contain only alphanumeric characters [a-z] and [A-Z]" ,'error' ); } if( ! (preg_match("/^[a-zA-Z]+$/", $_POST['billing_city']))){ wc_add_notice( "The City should contain only alphanumeric characters [a-z] and [A-Z]" ,'error' ); } }
Archive by Author: Kulcsár Péter
Limit Checkout Phone field to 10 numbers – Validation
// You can add a custom placeholder to add a hint for your CUs what you expect add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields2' ); // Our hooked in function - $fields is passed via the filter! function custom_override_checkout_fields2( $fields ) { $fields['billing']['billing_phone']['placeholder'] = '09XXXXXXXXX'; return $fields; } /****************************************************************/ /* VALIDATION FOR PHONE FIELD THIS WILL THROW AN ERROR MESSAGE */ /****************************************************************/ /** * Process the checkout ** add_action('woocommerce_checkout_process', 'my_custom_checkout_field_process'); function my_custom_checkout_field_process() { global $woocommerce; // Check if set, if its not set add an error. This one is only requite for companies if ( ! (preg_match('/^[0-9]{10}$/D', $_POST['billing_phone'] ))){ wc_add_notice( "The Phone should contain only 10 digits" ,'error' ); } }
WooCommerce – Show the smallest variation price with from X
/*********************************************************************/ /* SHOW ONLY THE SMALLEST VARIATION PRICE */ /*********************************************************************/ add_filter( 'woocommerce_variable_sale_price_html', 'wc_wc20_variation_price_format', 10, 2 ); add_filter( 'woocommerce_variable_price_html', 'wc_wc20_variation_price_format', 10, 2 ); function wc_wc20_variation_price_format( $price, $product ) { // Main Price $prices = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'max', true ) ); $price = $prices[0] !== $prices[1] ? sprintf( __( 'od %1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] ); // Sale Price $prices = array( $product->get_variation_regular_price( 'min', true ), $product->get_variation_regular_price( 'max', true ) ); sort( $prices ); $saleprice = $prices[0] !== $prices[1] ? sprintf( __( 'od %1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] ); if ( $price !== $saleprice ) { $price = '<del>' . $saleprice . '</del> <ins>' . $price . '</ins>'; } return $price; }