WC_API_Products::delete_product_shipping_class( int $id )

Delete a product shipping class.


Description Description


Parameters Parameters

$id

(Required) Product shipping class term ID


Top ↑

Return Return

(array|WP_Error) Success message if succeed, otherwise WP_Error will be returned


Top ↑

Source Source

File: includes/legacy/api/v3/class-wc-api-products.php

3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
public function delete_product_shipping_class( $id ) {
    global $wpdb;
 
    try {
        // Check permissions
        if ( ! current_user_can( 'manage_product_terms' ) ) {
            throw new WC_API_Exception( 'woocommerce_api_user_cannot_delete_product_shipping_class', __( 'You do not have permission to delete product shipping classes', 'woocommerce' ), 401 );
        }
 
        $id      = absint( $id );
        $deleted = wp_delete_term( $id, 'product_shipping_class' );
        if ( ! $deleted || is_wp_error( $deleted ) ) {
            throw new WC_API_Exception( 'woocommerce_api_cannot_delete_product_shipping_class', __( 'Could not delete the shipping class', 'woocommerce' ), 401 );
        }
 
        do_action( 'woocommerce_api_delete_product_shipping_class', $id, $this );
 
        return array( 'message' => sprintf( __( 'Deleted %s', 'woocommerce' ), 'product_shipping_class' ) );
    } catch ( WC_API_Exception $e ) {
        return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
    }
}

Top ↑

Changelog Changelog

Changelog
Version Description
2.5.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.