【问题标题】: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;
}