【发布时间】:2022-01-04 17:38:02
【问题描述】:
我需要从这个输入中给出价值:
<select name="sample" id="select_rent" class="select" style="border-radius: 6px; padding: 10px; padding-right:40px;">
<option value="<?php echo get_post_meta(get_the_ID(), 'rent_price_1', true ); ?>">1</option>
<option value="<?php echo get_post_meta(get_the_ID(), 'rent_price_3', true ); ?>">3</option>
<option value="<?php echo get_post_meta(get_the_ID(), 'rent_price_6', true ); ?>">6</option>
<option value="<?php echo get_post_meta(get_the_ID(), 'rent_price_12', true ); ?>">12</option>
<option value="<?php echo get_post_meta(get_the_ID(), 'rent_price_24', true ); ?>">24</option>
</select>
到这个php代码(作为变量select_value):
add_action( 'woocommerce_before_calculate_totals', 'add_custom_price', 1000, 1);
function add_custom_price( $cart ) {
// This is necessary for WC 3.0+
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
// Avoiding hook repetition (when using price calculations for example | optional)
if ( did_action( 'woocommerce_before_calculate_totals' ) >= 2 )
return;
// Loop through cart items
foreach ( $cart->get_cart() as $cart_item ) {
$cart_item['data']->set_price( $select_value );
}
}
我有这个原始的 ajax,不知道该怎么办:
<script type="text/javascript">
jQuery(function ($) {
$('#select_rent').change(function () {
var workselected = $(this).val();
$.ajax({
method: "POST",
url: "url",
data: $('#select_rent').val(),
success: function (data) {
console.log($('#select_rent').val());
}
});
});
})
</script>
ajax 不起作用400 (Bad Request),我不知道如何为 php 赋予价值。有人可以帮忙吗?
我修复了 ajax,现在它控制台记录值。我怎样才能把它交给php?
【问题讨论】:
标签: php ajax wordpress woocommerce