Skip to content

Commit

Permalink
fix: show notice if product SKU is not unique while updating product (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
saimonh3 authored and sabbir1991 committed Apr 17, 2019
1 parent 307c329 commit ff7b23e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
9 changes: 9 additions & 0 deletions classes/template-products.php
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,17 @@ public function handle_product_update() {

do_action( 'dokan_product_updated', $post_id, $postdata );


$redirect = apply_filters( 'dokan_add_new_product_redirect', dokan_edit_product_url( $post_id ), $post_id );

// if any error inside dokan_process_product_meta function
global $woocommerce_errors;

if ( $woocommerce_errors ) {
wp_redirect( add_query_arg( array( 'errors' => array_map( 'urlencode', $woocommerce_errors ) ), $redirect ) );
exit;
}

wp_redirect( add_query_arg( array( 'message' => 'success' ), $redirect ) );
exit;
}
Expand Down
2 changes: 1 addition & 1 deletion includes/wc-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function dokan_process_product_meta( $post_id, $data = [] ) {
$unique_sku = wc_product_has_unique_sku( $post_id, $new_sku );

if ( ! $unique_sku ) {
$woocommerce_errors[] = ( __( 'Product SKU must be unique.', 'dokan-lite' ) );
$woocommerce_errors[] = __( 'Product SKU must be unique', 'dokan-lite' );
} else {
update_post_meta( $post_id, '_sku', $new_sku );
}
Expand Down
17 changes: 9 additions & 8 deletions templates/products/new-product-single.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,17 @@
if ( ! $from_shortcode ) {
get_header();
}
?>

<?php
if ( ! empty( $_GET['errors'] ) ) {
Dokan_Template_Products::$errors = $_GET['errors'];
}

/**
* dokan_dashboard_wrap_before hook
*
* @since 2.4
*/
do_action( 'dokan_dashboard_wrap_before', $post, $post_id );
/**
* dokan_dashboard_wrap_before hook
*
* @since 2.4
*/
do_action( 'dokan_dashboard_wrap_before', $post, $post_id );
?>

<?php do_action( 'dokan_dashboard_wrap_start' ); ?>
Expand Down

0 comments on commit ff7b23e

Please sign in to comment.