public function orderByItemId($item_id)
    {
        if (!($item_id = (int) $item_id)) {
            return null; // Not possible.
        }
        $WpDb  = $this->s::wpDb(); // DB instance.
        $table = $WpDb->prefix.'woocommerce_order_items';

        $sql = /* Get the order ID for this item. */ '
            SELECT `order_id` FROM `'.esc_sql($table).'`
             WHERE `order_item_id` = %s LIMIT 1';
        $sql = $WpDb->prepare($sql, $item_id); // Prepare.

        if (!($order_id = (int) $WpDb->get_var($sql))) {
            return null; // Not possible; can't get order ID.
        } elseif (!($post_type = get_post_type($order_id))) {
            debug(0, $this->c::issue(vars(), 'Unable to acquire order post type.'));
            return null; // Not possible; can't get post type.
        }
        switch ($post_type) { // Based on post type.
            case 'shop_subscription':
                $subscription_id = $order_id; // It's a subscription ID.
                if (($WC_Subscription = wcs_get_subscription($subscription_id))) {
                    return $WC_Subscription;
                }
                return null; // Not possible.

            case 'shop_order':
            default: // Any other order type.
                if (($WC_Order = wc_get_order($order_id))) {
                    return $WC_Order;
                }
                return null; // Not possible.
        }
    }
public function orderByItemId($item_id)
    {
        if (!($item_id = (int) $item_id)) {
            return null; // Not possible.
        }
        $WpDb  = $this->s::wpDb(); // DB instance.
        $table = $WpDb->prefix.'woocommerce_order_items';

        $sql = /* Get the order ID for this item. */ '
            SELECT `order_id` FROM `'.esc_sql($table).'`
             WHERE `order_item_id` = %s LIMIT 1';
        $sql = $WpDb->prepare($sql, $item_id); // Prepare.

        if (!($order_id = (int) $WpDb->get_var($sql))) {
            return null; // Not possible; can't get order ID.
        } elseif (!($post_type = get_post_type($order_id))) {
            debug(0, $this->c::issue(vars(), 'Unable to acquire order post type.'));
            return null; // Not possible; can't get post type.
        }
        switch ($post_type) { // Based on post type.
            case 'shop_subscription':
                $subscription_id = $order_id; // It's a subscription ID.
                if (($WC_Subscription = wcs_get_subscription($subscription_id))) {
                    return $WC_Subscription;
                }
                return null; // Not possible.

            case 'shop_order':
            default: // Any other order type.
                if (($WC_Order = wc_get_order($order_id))) {
                    return $WC_Order;
                }
                return null; // Not possible.
        }
    }
public function orderByItemId ( $ item_id ) { if ( ! ( $ item_id = ( int ) $ item_id ) ) { return null ; // Not possible. } $ WpDb = $ this -> s :: wpDb ( ) ; // DB instance. $ table = $ WpDb -> prefix . 'woocommerce_order_items' ; $ sql = /* Get the order ID for this item. */ '
            SELECT `order_id` FROM `' . esc_sql ( $ table ) . '`
             WHERE `order_item_id` = %s LIMIT 1' ; $ sql = $ WpDb -> prepare ( $ sql , $ item_id ) ; // Prepare. if ( ! ( $ order_id = ( int ) $ WpDb -> get_var ( $ sql ) ) ) { return null ; // Not possible; can't get order ID. } elseif ( ! ( $ post_type = get_post_type ( $ order_id ) ) ) { debug ( 0 , $ this -> c :: issue ( vars ( ) , 'Unable to acquire order post type.' ) ) ; return null ; // Not possible; can't get post type. } switch ( $ post_type ) { // Based on post type. case 'shop_subscription' : $ subscription_id = $ order_id ; // It's a subscription ID. if ( ( $ WC_Subscription = wcs_get_subscription ( $ subscription_id ) ) ) { return $ WC_Subscription ; } return null ; // Not possible. case 'shop_order' : default : // Any other order type. if ( ( $ WC_Order = wc_get_order ( $ order_id ) ) ) { return $ WC_Order ; } return null ; // Not possible. } }
Get order containing item.

@since 160608 Order item utilities.

@param string|int $item_id Order item ID.

@return \WC_Abstract_Order|null Order on success.
Get order containing item .