mirror of
https://github.com/wp-graphql/wp-graphql-woocommerce.git
synced 2026-08-14 12:53:44 +02:00
"forceDelete" input field added for choosing between deletion and recycling.
This commit is contained in:
@@ -337,16 +337,15 @@ class Order_Mutation {
|
||||
/**
|
||||
* Purge object when creating.
|
||||
*
|
||||
* @param WC_Order|Order $order Object data.
|
||||
* @param AppContext $context AppContext instance.
|
||||
* @param ResolveInfo $info ResolveInfo instance.
|
||||
* @param WC_Order|Order $order Object data.
|
||||
* @param boolean $force_delete Delete or put in trash.
|
||||
*
|
||||
* @return bool
|
||||
* @throws UserError Failed to delete order.
|
||||
*/
|
||||
public static function purge( $order, $context, $info ) {
|
||||
public static function purge( $order, $force_delete = true ) {
|
||||
if ( is_callable( array( $order, 'delete' ) ) ) {
|
||||
return $order->delete( true );
|
||||
return $order->delete( $force_delete );
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -43,14 +43,18 @@ class Order_Delete {
|
||||
public static function get_input_fields() {
|
||||
$input_fields = array_merge(
|
||||
array(
|
||||
'id' => array(
|
||||
'id' => array(
|
||||
'type' => 'ID',
|
||||
'description' => __( 'Order global ID', 'wp-graphql-woocommerce' ),
|
||||
),
|
||||
'orderId' => array(
|
||||
'orderId' => array(
|
||||
'type' => 'Int',
|
||||
'description' => __( 'Order WP ID', 'wp-graphql-woocommerce' ),
|
||||
),
|
||||
'forceDelete' => array(
|
||||
'type' => 'Boolean',
|
||||
'description' => __( 'Delete or simply place in trash.', 'wp-graphql-woocommerce' ),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
@@ -100,6 +104,11 @@ class Order_Delete {
|
||||
throw new UserError( __( 'No order ID provided.', 'wp-graphql-woocommerce' ) );
|
||||
}
|
||||
|
||||
$force_delete = false;
|
||||
if ( ! empty( $input['forceDelete'] ) ) {
|
||||
$force_delete = $input['forceDelete'];
|
||||
}
|
||||
|
||||
// Get Order model instance for output.
|
||||
$order = new Order( $order_id );
|
||||
|
||||
@@ -124,11 +133,7 @@ class Order_Delete {
|
||||
do_action( 'woocommerce_graphql_before_order_delete', $order, $context, $info );
|
||||
|
||||
// Delete order.
|
||||
$success = Order_Mutation::purge(
|
||||
\WC_Order_Factory::get_order( $order->ID ),
|
||||
$context,
|
||||
$info
|
||||
);
|
||||
$success = Order_Mutation::purge( \WC_Order_Factory::get_order( $order->ID ), $force_delete );
|
||||
|
||||
if ( ! $success ) {
|
||||
throw new UserError(
|
||||
|
||||
Reference in New Issue
Block a user