Skip to content

Commit

Permalink
fix: product deleted issues
Browse files Browse the repository at this point in the history
  • Loading branch information
sabbir1991 committed Jan 1, 2020
1 parent 71e93f4 commit 51e59e0
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
1 change: 1 addition & 0 deletions dokan.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ function includes() {
function init_classes() {
new \WeDevs\Dokan\Withdraw\Hooks();
new \WeDevs\Dokan\Order\Hooks();
new \WeDevs\Dokan\Product\Hooks();
new \WeDevs\Dokan\Upgrade\Hooks();

if ( is_admin() ) {
Expand Down
37 changes: 30 additions & 7 deletions includes/Dashboard/Templates/Products.php
Original file line number Diff line number Diff line change
Expand Up @@ -457,20 +457,43 @@ function load_add_new_product_popup() {
* @return void
*/
function handle_delete_product() {

if ( ! is_user_logged_in() ) {
return;
}

if ( ! dokan_is_user_seller( get_current_user_id() ) ) {
if ( ! dokan_is_user_seller( dokan_get_current_user_id() ) ) {
return;
}

if ( ! current_user_can( 'dokan_delete_product' ) ) {
return;
}

dokan_delete_product_handler();
if ( isset( $_GET['action'] ) && $_GET['action'] == 'dokan-delete-product' ) {
$product_id = isset( $_GET['product_id'] ) ? (int) $_GET['product_id'] : 0;

$getdata = wp_unslash( $_GET );

if ( ! $product_id ) {
wp_redirect( add_query_arg( array( 'message' => 'error' ), dokan_get_navigation_url( 'products' ) ) );
return;
}

if ( ! wp_verify_nonce( $getdata['_wpnonce'], 'dokan-delete-product' ) ) {
wp_redirect( add_query_arg( array( 'message' => 'error' ), dokan_get_navigation_url( 'products' ) ) );
return;
}

if ( ! dokan_is_product_author( $product_id ) ) {
wp_redirect( add_query_arg( array( 'message' => 'error' ), dokan_get_navigation_url( 'products' ) ) );
return;
}

dokan()->product->delete( $product_id, true );

do_action( 'dokan_product_deleted', $product_id );

$redirect = apply_filters( 'dokan_add_new_product_redirect', dokan_get_navigation_url( 'products' ), '' );

wp_redirect( add_query_arg( array( 'message' => 'product_deleted' ), $redirect ) );
exit;
}
}

}
2 changes: 1 addition & 1 deletion includes/Product/Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function bulk_product_delete( $action, $products ) {

foreach ( $products as $product_id ) {
if ( dokan_is_product_author( $product_id ) ) {
wp_delete_post( $product_id );
dokan()->product->delete( $product_id, true );
}
}

Expand Down
4 changes: 2 additions & 2 deletions includes/Product/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,10 @@ public function update( $args = [] ) {
*
* @return void
*/
public function delete( $product_id ) {
public function delete( $product_id, $force = false ) {
$product = $this->get( $product_id );
if ( $product ) {
$product->delete( [ 'force_delete' => true ] );
$product->delete( [ 'force_delete' => $force ] );
}

return $product;
Expand Down

0 comments on commit 51e59e0

Please sign in to comment.