Sum the total amount of a specific product purchased per user and display in table

WooCommerce: Get Order info for all users. I was trying to help you get going.. After a while i had a complete solution :S… So here it is, a tested single shortcode that outputs your <table> (WooCommerce 3+ only): add_shortcode(‘user_order_info_table’, ‘sc_user_order_info_table_callback’); function sc_user_order_info_table_callback() { $result_array = array(); $users = get_users(); if($users) { foreach ($users as … Read more

How to get related tags based on a category?

You can get such tags using plain SQL query: global $wpdb; $wpdb->get_results( $wpdb->prepare( “SELECT tags.*, COUNT(tags_rel.object_id) as posts_count FROM {$wpdb->prefix}terms tags INNER JOIN {$wpdb->prefix}term_taxonomy tags_tax ON (tags_tax.term_id = tags.term_id) INNER JOIN {$wpdb->prefix}term_relationships tags_rel ON (tags_tax.term_taxonomy_id = tags_rel.term_taxonomy_id) INNER JOIN {$wpdb->prefix}posts posts ON (tags_rel.object_id = posts.ID) INNER JOIN {$wpdb->prefix}term_relationships cats_rel ON (posts.ID = cats_rel.object_id) INNER JOIN … Read more

How to handle 400 status in Ajax [duplicate]

This function will load the JS scripts: function test_ajax_load_scripts() { // load our jquery file that sends the $.post request wp_enqueue_script( “ajax-test”, plugin_dir_url( __FILE__ ) . ‘/ajax-test.js’, array( ‘jquery’ ) ); // make the ajaxurl var available to the above script wp_localize_script( ‘ajax-test’, ‘the_ajax_script’, array( ‘ajaxurl’ => admin_url( ‘admin-ajax.php’ ) ) ); } add_action(‘wp_print_scripts’, ‘test_ajax_load_scripts’);

Order by summing multiple values

I wouldn’t use taxonomies or custom fields for this purpose. Every time you’re add one custom field for a query, you have to add a JOIN part for that query – it means that with 10-15 custom fields, you’ll get query with 10-15 joins – so such query will be very slow. But there is … Read more