嗨,我正在尝试通过AJAX调用获取woocommerce订单对象,以更新一个订单元数据。
我在footer.php中有这个
<?php
var order_id = jQuery(this).attr('second_attr');
var sticker_id = jQuery(this).attr('first_attr');
jQuery.ajax({
type: "POST",
url: '/wp-content/themes/savoy-child/templates/sticker_to_order.php',
data: {order_id_value: order_id, sticker_id_value: sticker_id},
success: function(data){
alert(data);
}
});?>
然后在新文件Sticker_to_order.php中,我只有这个:
<?php
require_once('../../../../wp-load.php');
global $woocommerce;
$order_id =$_POST['order_id_value'];
$sticker_id = $_POST['sticker_id_value'];
$order_id = intval($order_id);
$order = wc_get_order( $order_id );
echo $order->get_id();
?>
但是它不起作用,控制台向我显示:
“ PHP致命错误:未捕获错误:在bool中调用成员函数get_id()……”