【问题标题】:Get total price after ajax update in woocommerce在 woocommerce 中更新 ajax 后获取总价
【发布时间】:2017-01-21 19:28:02
【问题描述】:

我试图在过滤器woocommerce_update_order_review_fragments 中获取价格,但无法理解它的位置

add_filter('woocommerce_update_order_review_fragments', 'price_bottom_checkout');
function price_bottom_checkout($arr) {
    $price = ? // how to get it over here?      
    $price_txt = '<span class="total-pay">'.$price.'</span>';
    $arr['.total-pay'] = $price;
    return $arr;
}

【问题讨论】:

    标签: wordpress woocommerce hook-woocommerce woocommerce-rest-api


    【解决方案1】:

    设法找出方法。需要查看每次通过 ajax 刷新购物车时更新的会话购物车。

    add_filter('woocommerce_update_order_review_fragments', 'price_bottom_checkout');
    function price_bottom_checkout($arr) {
        global $woocommerce;
        $the_total = '';
        foreach ($woocommerce->cart->cart_contents as $cart_item) {
            $the_total = $cart_item['line_total'];
            break;
        }
        $price_txt = '<span class="total-pay">'.wc_price($the_total).'</span>';
        $arr['.total-pay'] = $price_txt;
        return $arr;
    }
    

    【讨论】:

      猜你喜欢
      • 2016-10-31
      • 2016-03-18
      • 2020-07-20
      • 2017-09-10
      • 2021-04-23
      • 1970-01-01
      • 1970-01-01
      • 2014-11-26
      • 1970-01-01
      相关资源
      最近更新 更多