在我的页面模板中,我在
获取页脚();
<script>
jQuery(function($){
$( "#submit_prce" ).submit(function(e) {
var ajaxurl="<?php echo get_stylesheet_directory_uri().'/functions.php';?>";
e.preventDefault();
var data = {
action: 'update_price',
whatever: $("#price").val()
};
jQuery.post(ajaxurl, data, function(response) {
alert('Got this from the server: ' + response);
e.preventDefault();
});
});
});
</script>
我在中编写了以下函数函数.php
add_action('wp_ajax_update_price', 'update_pp_price');
add_action('wp_ajax_nopriv_update_price', 'update_pp_price');
function update_pp_price($given_price){
update_post_meta( 376, '_regular_price', $given_price );
update_post_meta( 376, '_price', $given_price );
}
但不知什么原因它不起作用。它显示了以下错误
从服务器上得到:
<b>Fatal error</b>: Call to undefined function add_filter() in <b>/home/myshop/public_html/wp-content/themes/mytheme-child/functions.php</b> on line <b>14</b><br />