Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save luanarup/81ddcea8d680e3524ef0fd075d0d8b29 to your computer and use it in GitHub Desktop.
Save luanarup/81ddcea8d680e3524ef0fd075d0d8b29 to your computer and use it in GitHub Desktop.
Como tornar o campo de preço e imagem obrigatório no Dokan
/**
* Adição de validação para imagem de capa do produto
*
* @param array $errors
* @return array $errors
*/
function dokan_can_add_product_validation_customized( $errors ) {
$postdata = wp_unslash( $_POST );
$featured_image = absint( sanitize_text_field( $postdata['feat_image_id'] ) );
$_regular_price = absint( sanitize_text_field( $postdata['_regular_price'] ) );
if ( isset( $postdata['feat_image_id'] ) && empty( $featured_image ) && ! in_array( 'Carregue uma imagem de capa do produto' , $errors ) ) {
$errors[] = 'Please upload a product cover image';
}
if ( isset( $postdata['_regular_price'] ) && empty( $_regular_price ) && ! in_array( 'Insira o preço do produto' , $errors ) ) {
$errors[] = 'Insira o preço do produto';
}
return $errors;
}
add_filter( 'dokan_can_add_product', 'dokan_can_add_product_validation_customized', 35, 1 );
add_filter( 'dokan_can_edit_product', 'dokan_can_add_product_validation_customized', 35, 1 );
function dokan_new_product_popup_validation_customized( $errors, $data ) {
if ( isset( $data['_regular_price'] ) && ! $data['_regular_price'] ) {
return new WP_Error( 'no-price', __( 'Insira o preço do produto', 'dokan-lite' ) );
}
if ( isset( $data['feat_image_id'] ) && ! $data['feat_image_id'] ) {
return new WP_Error( 'no-image', __( 'Selecione PELO MENOS UMA IMAGEM', 'dokan-lite' ) );
}
}
add_filter( 'dokan_new_product_popup_args', 'dokan_new_product_popup_validation_customized', 35, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment