Last active
August 29, 2015 14:18
-
-
Save helgatheviking/7df5e0cc7bf283107163 to your computer and use it in GitHub Desktop.
WooCommerce Name Your Price: Make NYP field required
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| add_filter( 'woocommerce_add_to_cart_validation', 'woocommerce_nyp_make_field_required', 10, 5 ); | |
| function woocommerce_nyp_make_field_required( $passed, $product_id, $quantity, $variation_id = '', $variations= '' ) { | |
| if( $variation_id ) | |
| $product_id = $variation_id; | |
| // skip if not a nyp product - send original status back | |
| if ( ! WC_Name_Your_Price_Helpers::is_nyp( $product_id ) ){ | |
| return $passed; | |
| } | |
| $posted_nyp_field = 'nyp' . apply_filters( 'nyp_field_prefix', '', $product_id ); | |
| $input = $_POST[ $posted_nyp_field ]; | |
| // set a null string to 0 | |
| if ( ! isset( $_POST[ $posted_nyp_field ] ) || empty( $_POST[ $posted_nyp_field ] ) ){ | |
| $passed = false; | |
| wc_add_notice( 'You really need to enter something.', 'error' ); | |
| } | |
| return $passed; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment