WooCommerce get_price returning wrong price when used via ajax

It’s important to exit the function when using the wp_ajax hooks. Hopefully this fixes it. function get_ticket_price() { $ticketID = $_REQUEST[‘ticketID’]; echo wc_get_product( $ticketID )->get_price(); // Don’t forget to stop execution afterward. wp_die(); } add_action( ‘wp_ajax_get_ticket_price’, ‘get_ticket_price’ ); add_action( ‘wp_ajax_nopriv_get_ticket_price’, ‘get_ticket_price’ );

How to run JS, PHP and etc. inside WP post?

Natively WordPress posts are subset of HTML (even more like semi-HTML – paragraph tags can be implied and added on output, but not stored). As result it really really doesn’t like to store or process active code in post’s content. This applies both to internal logic in PHP and front-end logic of post editor (it … Read more

WordPress ajax problem need wordpress expert?

The answer is quite simple – you are not giving admin-ajax what it is expecting. Please refer to the source code http://core.trac.wordpress.org/browser/tags/3.2.1/wp-admin/admin-ajax.php#L17 if ( ! isset( $_REQUEST[‘action’] ) ) die(‘-1’); So make sure you are giving it an action (which you are not). Then, a little lower there is: if ( ! $id ) die(‘-1’); … Read more