Php 我需要帮助从用户输入中更改价格
如何根据用户输入设置自定义价格?此自定义价格是硬编码的。有什么建议吗?类似于函数add_custom_price$cart_object$custom_pricePhp 我需要帮助从用户输入中更改价格,php,wordpress,Php,Wordpress,如何根据用户输入设置自定义价格?此自定义价格是硬编码的。有什么建议吗?类似于函数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 = $var
<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>