Automattic\WooCommerce\Internal\Admin\Orders\MetaBoxes

CustomMetaBox::verify_order_edit_permission_for_ajax()privateWC 1.0

Helper method to verify order edit permissions.

{} It's a method of the class: CustomMetaBox{}

No Hooks.

Return

?WC_Order. WC_Order object if the user can edit the order, die otherwise.

Usage

// private - for code of main (parent) class only
$result = $this->verify_order_edit_permission_for_ajax( $order_id ): ?WC_Order;
$order_id(int) (required)
Order ID.

Code of CustomMetaBox::verify_order_edit_permission_for_ajax() WC 7.1.0

private function verify_order_edit_permission_for_ajax( int $order_id ): ?WC_Order {
	if ( ! current_user_can( 'manage_woocommerce' ) || ! current_user_can( 'edit_others_shop_orders' ) ) {
		wp_send_json_error( 'missing_capabilities' );
		wp_die();
	}

	$order = wc_get_order( $order_id );
	if ( ! $order ) {
		wp_send_json_error( 'invalid_order_id' );
		wp_die();
	}
	return $order;
}