Why doesn’t this simple hook function work?
-
In my child function.php i have this:
function adjust_tax() { echo "start!"; global $woocommerce; $items = $woocommerce->cart->get_cart(); if ( is_admin() && ! defined( 'DOING_AJAX' ) ) echo "(adm.)"; return; if ( did_action( 'woocommerce_before_calculate_totals' ) >= 2 ) echo "(did.)"; return; if ( ! WC()->cart && WC()->cart->is_empty() ) echo "(Cart empty)."; return; $targeted_product_ids = array(221, 224); // Here define your specific products $subtotal = 0; // Loop through cart items (1st loop - get cart subtotal) foreach ( $items as $cart_item ) { echo "yes"; $subtotal += $cart_item['line_total']; } echo "Totalt: "; echo "Totalt: " . $subtotal; } function wc_cart_debug_all( $cart ) { global $woocommerce; $items = $woocommerce->cart->get_cart(); echo "<pre>"; print_r($items); echo "</pre>"; } add_action( 'woocommerce_before_cart', 'adjust_tax'); add_action( 'woocommerce_before_cart', 'wc_cart_debug_all' );After putting something in cart, the wc_cart_debug_all works fine, printing all.
For some reason, the adjust_tax function is acting weird.
It prints “start!” on the page right after the debug lines (and before the actual products showing), but nothing more.Obviously the function is not finished, and probably logic errors, but why doesn’t any of the “Totalt:” strings gets echoed?? Not even any “yes” is echoed.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
The topic ‘Why doesn’t this simple hook function work?’ is closed to new replies.