如何根据用户输入设置自定义价格?此自定义价格是硬编码的。有什么建议?类似函数add_custom_price($ cart_object,$ custom_price)
<code>add_action( 'woocommerce_before_calculate_totals', 'add_custom_price' );
function add_custom_price( $cart_object,$custom_price ) {
$custom_price = $variable_from_input; // This will be my custom input variable
foreach ( $cart_object->cart_contents as $key => $value ) {
$value['data']->price = $custom_price;
}
}</code>