简体   繁体   English

Woocommerce,wordpress

[英]Woocommerce, wordpress

I am developing a shop online with wordpress and woocommerce.我正在使用 wordpress 和 woocommerce 开发在线商店。 The price of the products depends on the size of them.产品的价格取决于它们的大小。 I use € x meters.我使用€ x 米。 When the costumer add one product on the cart, I update the custom price WP-Sesseion, but when the customer add other one, the total price is not ok.当客户在购物车上添加一种产品时,我更新了自定义价格 WP-Sesseion,但是当客户添加其他产品时,总价格不正确。 I get the price from a externar server inside of json file, and uptate it in a WP_session.我从 json 文件中的外部服务器获取价格,并在 WP_session 中更新它。 Then get the price in funciton.php and update the price of the cart.然后在 funciton.php 中获取价格并更新购物车的价格。

 function action_woocommerce_review_order_after_submit( $cart_object) {

$custom_price = WC()->session->get( 'price_project' ); // This will be your custome price
$target_product_id = WC()->session->get( 'product_id' );
foreach ( $cart_object->cart_contents as $value ) {
if ( $value['product_id'] == $target_product_id ) {
     WC()->session->set( 'price' , $custom_price );
$value['data']->price = $custom_price;
}
}
}

do_action( 'woocommerce_after_calculate_totals', 'action_woocommerce_review_order_after_submit');

Any suggestions?有什么建议么? Thanks you谢谢

您可能需要使用钩子 woocommerce_before_calculate_totals,因为在这种情况下,您进行价格调整后,购物车会更新总计。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM