WC_API_Products::delete_product_shipping_class()publicWC 2.5.0

Delete a product shipping class.

Метод класса: WC_API_Products{}

Возвращает

Массив|WP_Error. Success message if succeed, otherwise WP_Error will be returned

Использование

$WC_API_Products = new WC_API_Products();
$WC_API_Products->delete_product_shipping_class( $id );
$id(int) (обязательный)
Product shipping class term ID

Список изменений

С версии 2.5.0 Введена.

Код WC_API_Products::delete_product_shipping_class() WC 8.7.0

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() ) );
	}
}