Пример #1
0
    /**
     * Actually change subscription prices in cart (add signup fee, apportion if needed etc).
     * 
     * @access public
     * @param object $cart
     * @return void
     */
    public function change_prices($cart)
    {
        if ($this->cart_prices_changed || empty($cart->cart_contents)) {
            return;
        }

        // Iterate over all cart items and check if price needs to be updated for subscriptions
        foreach ($cart->cart_contents as $cart_item_key => $cart_item) {
            $id = !empty($cart_item['variation_id']) ? $cart_item['variation_id'] : $cart_item['product_id'];

            // Check if given item is subscription
            if (Subscriptio_Subscription_Product::is_subscription($id)) {

                // Get new price (or false if price does not need to be changed)
                $new_price = Subscriptio_Subscription_Product::get_new_price($id, $cart_item['data']->price);

                // Needs to be changed?
                if ($new_price !== false) {
                    global $woocommerce;

                    if (isset($woocommerce->cart->cart_contents[$cart_item_key])) {
                        $woocommerce->cart->cart_contents[$cart_item_key]['data']->price = $new_price;
                    }
                }
            }
        }

        $this->cart_prices_changed = true;
    }