Automattic\WooCommerce\Internal\DataStores\Orders

HposOrderCapabilityHelper::map_delete_order_capsprivateWC 1.0

Map delete capabilities for an HPOS order without a real order post.

Method of the class: HposOrderCapabilityHelper{}

No Hooks.

Returns

String[]. Required primitive capabilities.

Usage

// private - for code of main (parent) class only
$result = $this->map_delete_order_caps( $order, $order_type_ob, $user_id, ?WP_Post $post ): array;
$order(WC_Abstract_Order) (required)
Order object.
$order_type_ob(WP_Post_Type) (required)
Order post type object.
$user_id(int) (required)
User ID.
?WP_Post $post(required)
.

HposOrderCapabilityHelper::map_delete_order_caps() code WC 11.0.0

private function map_delete_order_caps( WC_Abstract_Order $order, WP_Post_Type $order_type_ob, int $user_id, ?WP_Post $post ): array {
	$status  = $this->get_wp_status_for_order( $order );
	$is_mine = $user_id === $this->get_author_id( $post );

	if ( $is_mine ) {
		if ( $this->is_published_status( $status ) ) {
			return array( $order_type_ob->cap->delete_published_posts );
		}
		if ( 'trash' === $status && $this->is_published_status( $this->get_trashed_status( $order ) ) ) {
			return array( $order_type_ob->cap->delete_published_posts );
		}
		return array( $order_type_ob->cap->delete_posts );
	}

	$caps = array( $order_type_ob->cap->delete_others_posts );
	if ( $this->is_published_status( $status ) ) {
		$caps[] = $order_type_ob->cap->delete_published_posts;
	} elseif ( $this->is_private_status( $status ) ) {
		$caps[] = $order_type_ob->cap->delete_private_posts;
	}

	return $caps;
}