I would appreciate it if anyone can help me before I give up on wordpress altogether. I’ve been trying to do a so called “simple” enqueue ha! for at least 3 weeks. I’m trying to install a price table on my product page using my custom jQuery script. I’ve been to google, the forums, read the codex etc... Followed over 25 different enqueue and register script examples only to get Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'pricetable' not found or invalid function name in public_html/wp-includes/plugin.php on line 470. just a few examples I've tried are...
function theme_name_scripts() {
wp_enqueue_style( 'style.css', get_stylesheet_uri() );
wp_enqueue_script('pricetable',get_stylesheet_directory_uri()
. 'pricetable.js', array('jquery'), '1.0.0', false );
}
add_action( 'wp_enqueue_scripts', 'theme_name_scripts' );
function my_scripts_method() {
wp_enqueue_script(
'jquery',
get_template_directory_uri() . 'pricetable.js',
array('jquery')
);
}
add_action('wp_enqueue_scripts', 'my_scripts_method');
add_action('woocommerce_single_product_summary','pricetable');`
function custom_scripts() {
wp_register_script( 'jQuery', 'http://wp-content/themes/wootique-child/pricetable.js', array( 'jquery'), '1.0.0', false );
wp_enqueue_script( 'jQuery' );
}
add_action( 'wp_enqueue_scripts', 'custom_scripts' );
My pricetable script starts...
jQuery(document).ready (function($) {
var x = document.createElement("TABLE");
x.setAttribute("id", "pricetable");
document.body.appendChild(x);
I’m using a wootique-child theme and have installed woocommerce, a function.php, header file, etc… in its child directory. I’ve tested the function file by writing a simple “hello world” function and placing “hello world” in different areas of the product page using action and filter hooks. I’ve also placed my no-conflict anonymous jQuery “pricetable” script in the child themes header which allows the table to be displayed and manipulated by the child style.css file on the product page. However the product page hooks that I’ve placed at the end of the script don’t work and it doesn’t matter if their commented out or not. This might be the reason the table is appended to one side of the product page and the table data is slightly off center. That problem could probably be fixed by tweaking the css file. The strange thing is that the table only appears on the product page, like it supposed to, without the aid of the product page hooks?
I would like to use my child function.php to call the “pricetable.js” file the correct way so that I can clean up my templates and use the add action and filter hooks to place the table in the proper area of the product page. Neither the literature nor examples indicate where any of the files they mention need to be placed. Therefore I’ve placed my “pricetable.js” file in several different areas to try and make it work. In the child theme I placed the pricetable.js file directly in its subdirectory using the wp-content /themes /wootique-child/ pricetable.js path. In both the parent and child theme I also placed the “pricetable” file in wp-content/themes /wootique(child) /includes/js/ pricetable.js. I’ve tried enqueue in both the child and parent theme. Whatever file path I use, method of register or enqueue, wordpress can’t locate the "pricetable.js" file.
It also would be nice to know the proper syntax so I can use the hooks as a variable in my script to retrieve the products base price to use in the table.
Thank you I appreciate your help