• Hi I already sent you an e-mail, but I figured that this might be faster.

    I wrote this function that generates a subtotal of all the prices of the products within a certain category in the cart:

    function cat_cart_sum() {
            if ( ! is_page( 'winkelmand' ) ) {
            return;
        }
        $cat_count = 0; 
        // Iterating through each cart item
        foreach(WC()->cart->get_cart() as $cart_item)  
            if( has_term( 'Geen actie artikelen', 'product_cat', $cart_item['product_id'])) {
                $regularprice = $cart_item['data']->get_price();
                $price = $regularprice * $cart_item['quantity'];
                $cat_count += $price;
            }
        if ($cat_count >= 40 && $cat_count <= 100) {
                                   wc_add_notice('U krijgt bij het afhalen €10 gratis vuurwerk!', 'notice');
                                   } elseif ($cat_count > 100 && $cat_count <= 200) {
                wc_add_notice('U krijgt bij het afhalen €25 gratis vuurwerk!', 'notice');
            } elseif ($cat_count > 200 && $cat_count <= 300) {
                wc_add_notice('U krijgt bij het afhalen €50 gratis vuurwerk!', 'notice');
            } elseif ($cat_count > 300 && $cat_count <= 400) {
                wc_add_notice('U krijgt bij het afhalen €75 gratis vuurwerk!', 'notice');
            } elseif ($cat_count >= 400) {
                wc_add_notice('U krijgt bij het afhalen €100 gratis vuurwerk!', 'notice');
            }
        return $cat_count;
    }

    What I’m looking for is a way that the $cat_count can be echoed onto the invoice. I was thinking of adding a hidden field to the order_meta or something like that, because calling the function inside of the invoice body.php doesn’t work at all.

    Kind regards,

    Daaf Bleumink

The topic ‘Function call messes up invoice’ is closed to new replies.