WC_API_Products::delete_product_tag() public WC 2.5.0
Delete a product tag.
{} It's a method of the class: WC_API_Products{}
Hooks from the method
Return
Array|WP_Error. Success message if succeed, otherwise WP_Error will be returned
Usage
$WC_API_Products = new WC_API_Products(); $WC_API_Products->delete_product_tag( $id );
- $id(int) (required)
- Product tag term ID
Changelog
Since 2.5.0 | Introduced. |
Code of WC_API_Products::delete_product_tag() WC API Products::delete product tag WC 5.0.0
public function delete_product_tag( $id ) {
try {
// Check permissions
if ( ! current_user_can( 'manage_product_terms' ) ) {
throw new WC_API_Exception( 'woocommerce_api_user_cannot_delete_product_tag', __( 'You do not have permission to delete product tag', 'woocommerce' ), 401 );
}
$id = absint( $id );
$deleted = wp_delete_term( $id, 'product_tag' );
if ( ! $deleted || is_wp_error( $deleted ) ) {
throw new WC_API_Exception( 'woocommerce_api_cannot_delete_product_tag', __( 'Could not delete the tag', 'woocommerce' ), 401 );
}
do_action( 'woocommerce_api_delete_product_tag', $id, $this );
return array( 'message' => sprintf( __( 'Deleted %s', 'woocommerce' ), 'product_tag' ) );
} catch ( WC_API_Exception $e ) {
return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
}
}