cart->cart_contents ) ) { foreach ( WC()->cart->cart_contents as $cart_item ) { if ( isset( $cart_item['subscription_initial_payment'] ) ) { $order = wc_get_order( $cart_item['subscription_initial_payment']['order_id'] ); if ( static::has_handled_stock( $order ) ) { $parent_order = $order; break; } } } } return $parent_order; } /** * Gets the parent order from order-pay query vars. * * @since 1.0.0 - Migrated from WooCommerce Subscriptions v3.0.6 * @return WC_Order|bool Parent order obtained from query vars or false if not set or if no handling is required. */ protected static function get_order_from_query_vars() { global $wp; $parent_order = false; if ( isset( $wp->query_vars['order-pay'] ) ) { $order = wc_get_order( $wp->query_vars['order-pay'] ); if ( $order && static::has_handled_stock( $order ) && wcs_order_contains_subscription( $order, 'parent' ) ) { $parent_order = $order; } } return $parent_order; } /** * Checks if an order has already reduced stock. * * @since 1.0.0 - Migrated from WooCommerce Subscriptions v3.0.6 * @param WC_Order $order * @return bool Whether the order has reduced stock. */ protected static function has_handled_stock( $order ) { return (bool) $order->get_data_store()->get_stock_reduced( $order->get_id() ); } }