Only delete if the object has an ID

This commit is contained in:
Mike Jolley 2017-05-30 14:44:28 +01:00
parent 7529e1ac26
commit ed32f9c792
4 changed files with 20 additions and 4 deletions

View File

@ -164,6 +164,10 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme
'force_delete' => false,
) );
if ( ! $id ) {
return;
}
if ( $args['force_delete'] ) {
wp_delete_post( $id );
$order->set_id( 0 );

View File

@ -179,12 +179,16 @@ class WC_Coupon_Data_Store_CPT extends WC_Data_Store_WP implements WC_Coupon_Dat
$id = $coupon->get_id();
if ( ! $id ) {
return;
}
if ( $args['force_delete'] ) {
wp_delete_post( $coupon->get_id() );
wp_delete_post( $id );
$coupon->set_id( 0 );
do_action( 'woocommerce_delete_coupon', $id );
} else {
wp_trash_post( $coupon->get_id() );
wp_trash_post( $id );
do_action( 'woocommerce_trash_coupon', $id );
}
}

View File

@ -41,6 +41,10 @@ class WC_Order_Refund_Data_Store_CPT extends Abstract_WC_Order_Data_Store_CPT im
public function delete( &$order, $args = array() ) {
$id = $order->get_id();
if ( ! $id ) {
return;
}
wp_delete_post( $id );
$order->set_id( 0 );
do_action( 'woocommerce_delete_order_refund', $id );

View File

@ -234,12 +234,16 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
'force_delete' => false,
) );
if ( ! $id ) {
return;
}
if ( $args['force_delete'] ) {
wp_delete_post( $product->get_id() );
wp_delete_post( $id );
$product->set_id( 0 );
do_action( 'woocommerce_delete_' . $post_type, $id );
} else {
wp_trash_post( $product->get_id() );
wp_trash_post( $id );
$product->set_status( 'trash' );
do_action( 'woocommerce_trash_' . $post_type, $id );
}