/ public function get_post_or_order_id( $post_or_order_object ) : int { if ( is_numeric( $post_or_order_object ) ) { return (int) $post_or_order_object; } elseif ( $post_or_order_object instanceof WC_Order ) { return $post_or_order_object->get_id(); } elseif ( $post_or_order_object instanceof WP_Post ) { return $post_or_order_object->ID; } return 0; } /** * Checks if passed id, post or order object is a WC_Order object. * * @param int|WP_Post|WC_Order $order_id Order ID, post object or order object. * @param string[] $types Types to match against. * * @return bool Whether the passed param is an order. */ public function is_order( $order_id, array $types = array( 'shop_order' ) ) : bool { $order_id = $this->get_post_or_order_id( $order_id ); $order_data_store = \WC_Data_Store::load( 'order' ); return in_array( $order_data_store->get_order_type( $order_id ), $types, true ); } /** * Returns type pf passed id, post or order object. * * @param int|WP_Post|WC_Order $order_id Order ID, post object or order object. * * @return string|null Type of the order. */ public function get_order_type( $order_id ) { $order_id = $this->get_post_or_order_id( $order_id ); $order_data_store = \WC_Data_Store::load( 'order' ); return $order_data_store->get_order_type( $order_id ); } /** * Get the name of the database table that's currently in use for orders. * * @return string */ public function get_table_for_orders() { if ( $this->custom_orders_table_usage_is_enabled() ) { $table_name = OrdersTableDataStore::get_orders_table_name(); } else { global $wpdb; $table_name = $wpdb->posts; } return $table_name; } /** * Get the name of the database table that's currently in use for orders. * * @return string */ public function get_table_for_order_meta() { if ( $this->custom_orders_table_usage_is_enabled() ) { $table_name = OrdersTableDataStore::get_meta_table_name(); } else { global $wpdb; $table_name = $wpdb->postmeta; } return $table_name; } }