-
-
Save bentasm1/1e458c0115fe12e96223 to your computer and use it in GitHub Desktop.
How to make a field required in WC Vendors Pro
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
To require, or not to require, that is the question...... In the future, we'll make these into checkboxes to require/not require, | |
but for now you use filters. Add this code to your themes functions.php file. Here's the process: | |
1.) Find the filter for the field you want to adjust the requirements. This file is in /plugins/wc-vendors-pro/public/forms/class-wcvendors-pro-product-form.php | |
2.) Create a filter for each field you'd like to make required (or not required). The code below will make the description required: | |
/* WC Vendors Pro - Make Description Required */ | |
function wcv_product_description_required( $args ) { | |
$args[ 'custom_attributes' ] = array( | |
'data-rules' => 'required', // Change 'required' to '' to make it not required (just remove the word required but keep the single quotes) | |
'data-error' => __( 'This field is required.', 'wcvendors-pro' ) | |
); | |
return $args; | |
} | |
add_filter( 'wcv_product_description', 'wcv_product_description_required' ); | |
3.) That's it! Have fun. | |
Some fields are REQUIRED already, such as title and description. To change this: | |
/* WC Vendors Pro - Make Description NOT Required */ | |
function wcv_product_description_required( $args ) { | |
$args[ 'custom_attributes' ] = array(); | |
return $args; | |
} | |
add_filter( 'wcv_product_description', 'wcv_product_description_required' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment