admin管理员组文章数量:1130349
Similar question: WooCommerce Dynamic Cart Pricing
function odb_add_length_price( $cart_object ) {
if( !(is_admin() && !defined('DOING_AJAX'))) {
foreach ( $cart_object->get_cart() as $cart_item ) {
$price = $cart_item['data']->get_price();
$price = 1 + $price;
$cart_item['data']->set_price( $price );
}
}
}
add_action( 'woocommerce_before_calculate_totals', 'odb_add_length_price', 10, 1);
If the product price is set to 100, then the total should be 101. The price returned is set to 103, for some reason it gets multiplied by 3.
If i remove the $price and set a static value to 100, the returned price is 101.
If i only return the price, the prices returns as 100.
So each time i combine or calculate get_price plus x, it multiplies by 3.
Similar question: WooCommerce Dynamic Cart Pricing
function odb_add_length_price( $cart_object ) {
if( !(is_admin() && !defined('DOING_AJAX'))) {
foreach ( $cart_object->get_cart() as $cart_item ) {
$price = $cart_item['data']->get_price();
$price = 1 + $price;
$cart_item['data']->set_price( $price );
}
}
}
add_action( 'woocommerce_before_calculate_totals', 'odb_add_length_price', 10, 1);
If the product price is set to 100, then the total should be 101. The price returned is set to 103, for some reason it gets multiplied by 3.
If i remove the $price and set a static value to 100, the returned price is 101.
If i only return the price, the prices returns as 100.
So each time i combine or calculate get_price plus x, it multiplies by 3.
Share Improve this question edited Oct 31, 2018 at 14:22 Nicolai Byø Friis asked Oct 30, 2018 at 9:53 Nicolai Byø FriisNicolai Byø Friis 11 silver badge3 bronze badges1 Answer
Reset to default 0The solution was to add remove_action( 'woocommerce_before_calculate_totals', 'odb_add_length_price', 10, 1); on the first line in the function.
This removes the function each time it run and works like expected.
Similar question: WooCommerce Dynamic Cart Pricing
function odb_add_length_price( $cart_object ) {
if( !(is_admin() && !defined('DOING_AJAX'))) {
foreach ( $cart_object->get_cart() as $cart_item ) {
$price = $cart_item['data']->get_price();
$price = 1 + $price;
$cart_item['data']->set_price( $price );
}
}
}
add_action( 'woocommerce_before_calculate_totals', 'odb_add_length_price', 10, 1);
If the product price is set to 100, then the total should be 101. The price returned is set to 103, for some reason it gets multiplied by 3.
If i remove the $price and set a static value to 100, the returned price is 101.
If i only return the price, the prices returns as 100.
So each time i combine or calculate get_price plus x, it multiplies by 3.
Similar question: WooCommerce Dynamic Cart Pricing
function odb_add_length_price( $cart_object ) {
if( !(is_admin() && !defined('DOING_AJAX'))) {
foreach ( $cart_object->get_cart() as $cart_item ) {
$price = $cart_item['data']->get_price();
$price = 1 + $price;
$cart_item['data']->set_price( $price );
}
}
}
add_action( 'woocommerce_before_calculate_totals', 'odb_add_length_price', 10, 1);
If the product price is set to 100, then the total should be 101. The price returned is set to 103, for some reason it gets multiplied by 3.
If i remove the $price and set a static value to 100, the returned price is 101.
If i only return the price, the prices returns as 100.
So each time i combine or calculate get_price plus x, it multiplies by 3.
Share Improve this question edited Oct 31, 2018 at 14:22 Nicolai Byø Friis asked Oct 30, 2018 at 9:53 Nicolai Byø FriisNicolai Byø Friis 11 silver badge3 bronze badges1 Answer
Reset to default 0The solution was to add remove_action( 'woocommerce_before_calculate_totals', 'odb_add_length_price', 10, 1); on the first line in the function.
This removes the function each time it run and works like expected.
本文标签: Adding price to woocommerce cart item with getprice gets multiplied with 3
版权声明:本文标题:Adding price to woocommerce cart item with get_price gets multiplied with 3? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749185757a2329359.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论