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 render a time-of-day string like ’16:42′ with a site’s chosen time format?

The trick here is using wp_date() in a peculiar way, giving it the time of day in seconds (as if it were 1970-01-01 16:42:18), then asking for it to be formatted in UTC. $time=”16:42:18″; if ( preg_match( ‘/^\d\d:\d\d:\d\d$/’, $time ) ) { //validate the $time $ts = intval( substr( $time, 0, 2 ) ) * … Read more

Where to call add_shortcode function in WordPress Plugin Boilerplate?

If you look at the /includes/class-plugin-loader.php you will see the public function add_shortcode( $tag, $component, $callback, $priority = 10, $accepted_args = 2 ) { $this->shortcodes = $this->add( $this->shortcodes, $tag, $component, $callback, $priority, $accepted_args ); } That builds a list of shortcodes to be registered with WordPress. You use that via /includes/class-plugin.php within this function: /** … Read more

Changing labels of status filters for post grid

Here’s an untested way to override it, based on my older answer: add_action( ‘init’, function() { $vars = get_object_vars( get_post_status_object( ‘draft’ ) ); $vars[‘label_count’] = _n_noop( ‘Disabled <span class=”count”>(%s)</span>’, ‘Disabled <span class=”count”>(%s)</span>’, ‘wpse-domain’ ); register_post_status( ‘draft’, $vars ); }, 1 ); We use the priority 1, since the default draft status is registered at priority … Read more

“Plugin could not be activated because it triggered a fatal error.”

The recommended way to write that function would be: function ce3_cleanup() { global $wpdb; $wpdb->query( “update $wpdb->postmeta set meta_key=replace(meta_key,’cb2_customHeader’,’_cb2_customHeader’) where meta_key like ‘cb2_customHeader'” ); $wpdb->query( “update $wpdb->postmeta set meta_key=replace(meta_key,’cb2_customTitle’,’_cb2_customTitle’) where meta_key like ‘cb2_customTitle'” ); } register_activation_hook( __FILE__, ‘ce3_cleanup’ );