public function productIdFromItem($WC_Order_Item): int
    {
        // WC 3.0+ uses `\WC_Order_Item_Product` extending `\WC_Order_Item`.
        // <https://docs.woocommerce.com/wc-apidocs/class-WC_Order_Item_Product.html>
        // <https://docs.woocommerce.com/wc-apidocs/class-WC_Order_Item.html>

        if ($WC_Order_Item instanceof \WC_Order_Item_Product) {
            if (($variation_id = $WC_Order_Item->get_variation_id())) {
                return (int) $variation_id;
            }
            return (int) $WC_Order_Item->get_product_id();
            //
        } elseif ($WC_Order_Item instanceof \WC_Order_Item) {
            return 0; // Not a product item.
            //
        } else { // Back compat.
            $item = (array) $WC_Order_Item;

            if (!empty($item['variation_id'])) {
                return (int) $item['variation_id'];
            }
            return (int) ($item['product_id'] ?? 0);
        }
    }
public function productIdFromItem($WC_Order_Item): int
    {
        // WC 3.0+ uses `\WC_Order_Item_Product` extending `\WC_Order_Item`.
        // <https://docs.woocommerce.com/wc-apidocs/class-WC_Order_Item_Product.html>
        // <https://docs.woocommerce.com/wc-apidocs/class-WC_Order_Item.html>

        if ($WC_Order_Item instanceof \WC_Order_Item_Product) {
            if (($variation_id = $WC_Order_Item->get_variation_id())) {
                return (int) $variation_id;
            }
            return (int) $WC_Order_Item->get_product_id();
            //
        } elseif ($WC_Order_Item instanceof \WC_Order_Item) {
            return 0; // Not a product item.
            //
        } else { // Back compat.
            $item = (array) $WC_Order_Item;

            if (!empty($item['variation_id'])) {
                return (int) $item['variation_id'];
            }
            return (int) ($item['product_id'] ?? 0);
        }
    }
public function productIdFromItem ( $ WC_Order_Item ) : int { // WC 3.0+ uses `\WC_Order_Item_Product` extending `\WC_Order_Item`. // <https://docs.woocommerce.com/wc-apidocs/class-WC_Order_Item_Product.html> // <https://docs.woocommerce.com/wc-apidocs/class-WC_Order_Item.html> if ( $ WC_Order_Item instanceof \ WC_Order_Item_Product ) { if ( ( $ variation_id = $ WC_Order_Item -> get_variation_id ( ) ) ) { return ( int ) $ variation_id ; } return ( int ) $ WC_Order_Item -> get_product_id ( ) ; // } elseif ( $ WC_Order_Item instanceof \ WC_Order_Item ) { return 0 ; // Not a product item. // } else { // Back compat. $ item = ( array ) $ WC_Order_Item ; if ( ! empty ( $ item [ 'variation_id' ] ) ) { return ( int ) $ item [ 'variation_id' ] ; } return ( int ) ( $ item [ 'product_id' ] ?? 0 ) ; } }
Get product ID from item.

@since 160608 Order item utilities.
@since 170417.43553 Accept `\WC_Order_Item`.

@param \WC_Order_Item|array $WC_Order_Item Order item.

@return int Product ID from item.
Get product ID from item .