dtpwra8456 2019-01-22 21:23
浏览 20

WooCommerce:购物车数量更新后的点火功能

I am trying to fire this script when the user updates cart quantity on my WordPress Cart page.

The script needs to have updated values for total, subtotal etc., whenever there is an update made on the Cart page. My idea was to use a WooCommerce action hook to fire the script after the cart product quantity has changed, so I can grab the latest, most up-to-date price. Below I am only testing one value, the grandTotal.

To give more context, there is an Update Cart button on the cart for when someone uses the arrows to increase or decrease the quantity, I need this to happen when someone hits the Update Cart button. I do not need the price to dynamically update when the quantity is changed. It should be done only once the Update Cart button has been clicked.

enter image description here

This does not work. Currently, with the below code, the Update Cart button breaks and does not update the quantity at all. The function also does not fire and nothing happens.

function updateCartPrice( $cart_item_key, $quantity, $old_quantity ) {
    if ( is_cart() ) { ?>

        <script type="text/javascript">
            bronto('cart:send', {
                "customerCartId": "cart_ABC123", // Set for testing. This value will be auto-generated when not set.
                "phase": "ORDER_COMPLETE", // Set as SHOPPING for Cart Recovery
                "currency": "USD",
                "subtotal": 35.98,
                "grandTotal": <?php echo WC()->cart->get_total() ?>,
                "customerOrderId": "123ABC", // Not necessary for Cart Recovery
                "emailAddress": "example@example.com",
            });
            console.log('test log');
        </script>


    <?php
    }
}

// add the action 
add_action( 'woocommerce_after_cart_item_quantity_update', 'updateCartPrice' );
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#Java#的问题,如何解决?
    • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
    • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥15 cmd cl 0x000007b
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
    • ¥500 火焰左右视图、视差(基于双目相机)
    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化