我的问题是如何将固定价格与产品小计en进行计算。 Woocommerce价格是基于数量的,但是我想用一定的价格在购物车总和中加上产品的小计:
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
// $cart_item['data']->set_price($custom_price);
$_product = wc_get_product( $cart_item['data']->get_id() );
$getProductDetail = wc_get_product( $cart_item['product_id'] );
$quantity_cr = $cart_item['quantity'];
$price = get_post_meta($cart_item['product_id'] , '_price', true);
/*Regular Price and Sale Price*/
//echo "Regular Price: ".get_post_meta($cart_item['product_id'] , '_regular_price', true)."<br>";
//echo "Sale Price: ".get_post_meta($cart_item['product_id'] , '_sale_price', true)."<br>";
$opdruk = $cart_item['thwepof_options'];
foreach($opdruk as $cr_item) {
$total_price_each_prduct = $cart_item['line_total'];
$opdruk_value = $cr_item['value'];
//print_r($opdruk_value);
if ($opdruk_value != "Geen opdruk") {
$price_opdruk = $price + 39; // this is the fixed price i want to add (not on quantity based)
}
}
}
答案 0 :(得分:2)
您好,您可以像在总价中添加税款/运费/等...
function prefix_add_price_line( $cart ) {
$add_price = 39;
$cart->add_fee( __( 'Vat Exempt Tax', 'yourtext-domain' ) , $add_price );
}
add_action( 'woocommerce_cart_calculate_fees', 'prefix_add_price_line' );
答案 1 :(得分:1)
尝试此代码
const Docker = require('dockerode')
const streams = require('memory-streams')
const docker = new Docker()
const stdout = new streams.WritableStream()
const stderr = new streams.WritableStream()
docker.run(
'debian:10',
['sh', '-c', 'echo test; echo testerr >/dev/stderr; echo test3'],
[stdout, stderr],
{ Tty: false }
)
.then(([ res, container ]) => {
console.log(res)
console.log('stdout: %j', stdout.toString())
console.log('stderr: %j', stderr.toString())
return container.remove()
})
.catch((error) => console.log(error))
答案 2 :(得分:0)
您可以尝试使用此挂钩:
function filter_woocommerce_cart_product_subtotal( $product_subtotal, $product, $quantity, $instance ) {
// some logic
return $product_subtotal;
};
// add the filter
add_filter( 'woocommerce_cart_product_subtotal', 'filter_woocommerce_cart_product_subtotal', 10, 4 );