1

我的functions.php中有这个动作:

add_action( 'woocommerce_before_calculate_totals', 'adding_custom_price', 10, 1);
function adding_custom_price( $cart ) {
global $current_user, $woocommerce, $wpdb;

    // This is necessary for WC 3.0+
    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
        return;

    // Avoiding hook repetition (when using price calculations for example)
    if ( did_action( 'woocommerce_before_calculate_totals' ) >= 2 )
        return;

            $quantity = 0;
                foreach ( $cart->get_cart() as $cart_item ) {
                    $quantity += $cart_item['quantity'];
                    $product_id = $cart_item['data']->get_id();
                    $product_price = $cart_item['data']->get_price();
                    $categorie_id = $cart_item['data']->get_category_ids();
                    $korting_product = get_field( 'discount_points', $product_id );

                    //Zet prijs min benegas korting
                    $cart_item['data']->set_price($product_price - $korting_product);
                }

echo "<script type='text/javascript'>alert('$quantity');</script>";

}

但是有了这条线:

echo "<script type='text/javascript'>alert('$quantity');</script>";

更改数量后购物车继续加载,所以我做错了什么。我没有收到警报。

4

0 回答 0