[API] Fixed edit coupon description, closes #8614
This commit is contained in:
parent
095162df15
commit
3a0d2f7c89
|
@ -358,8 +358,17 @@ class WC_API_Coupons extends WC_API_Resource {
|
|||
throw new WC_API_Exception( 'woocommerce_api_coupon_code_already_exists', __( 'The coupon code already exists', 'woocommerce' ), 400 );
|
||||
}
|
||||
|
||||
$id = wp_update_post( array( 'ID' => intval( $id ), 'post_title' => $coupon_code, 'post_excerpt' => isset( $data['description'] ) ? $data['description'] : '' ) );
|
||||
if ( 0 === $id ) {
|
||||
$updated = wp_update_post( array( 'ID' => intval( $id ), 'post_title' => $coupon_code ) );
|
||||
|
||||
if ( 0 === $updated ) {
|
||||
throw new WC_API_Exception( 'woocommerce_api_cannot_update_coupon', __( 'Failed to update coupon', 'woocommerce' ), 400 );
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $data['description'] ) ) {
|
||||
$updated = wp_update_post( array( 'ID' => intval( $id ), 'post_excerpt' => $data['description'] ) );
|
||||
|
||||
if ( 0 === $updated ) {
|
||||
throw new WC_API_Exception( 'woocommerce_api_cannot_update_coupon', __( 'Failed to update coupon', 'woocommerce' ), 400 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -358,8 +358,17 @@ class WC_API_Coupons extends WC_API_Resource {
|
|||
throw new WC_API_Exception( 'woocommerce_api_coupon_code_already_exists', __( 'The coupon code already exists', 'woocommerce' ), 400 );
|
||||
}
|
||||
|
||||
$id = wp_update_post( array( 'ID' => intval( $id ), 'post_title' => $coupon_code, 'post_excerpt' => isset( $data['description'] ) ? $data['description'] : '' ) );
|
||||
if ( 0 === $id ) {
|
||||
$updated = wp_update_post( array( 'ID' => intval( $id ), 'post_title' => $coupon_code ) );
|
||||
|
||||
if ( 0 === $updated ) {
|
||||
throw new WC_API_Exception( 'woocommerce_api_cannot_update_coupon', __( 'Failed to update coupon', 'woocommerce' ), 400 );
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $data['description'] ) ) {
|
||||
$updated = wp_update_post( array( 'ID' => intval( $id ), 'post_excerpt' => $data['description'] ) );
|
||||
|
||||
if ( 0 === $updated ) {
|
||||
throw new WC_API_Exception( 'woocommerce_api_cannot_update_coupon', __( 'Failed to update coupon', 'woocommerce' ), 400 );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue