Woocommerce – Shipping tax class based on cart items not using the highest tax available

I have found the answer by override the shipping tax filter // 0% and 21% tax producdts added combined to the cart needs to have 21% shipping tax add_filter(‘woocommerce_shipping_packages’, ‘override_woocommerce_shipping_packages’); function override_woocommerce_shipping_packages($packages) { $shipment_needs_tax = false; foreach ($packages[0][‘contents’] as $cartitem) { if (!empty($cartitem[‘data’]->tax_class)) $shipment_needs_tax = true; } if ($shipment_needs_tax && empty($packages[0][‘rates’][‘flat_rate:3’]->get_taxes())) { $shipcost = $packages[0][‘rates’][‘flat_rate:3’]->get_cost(); … Read more

How to limit posts to 1 from each term with tax_query?

<?php $categories = array(‘economy’,’the-constitution’,’monetary-policy’,’liberty’); foreach($categories as $category) { $args = array( ‘posts_per_page’ => 1, ‘category_name’ => $category, ‘tax_query’ => array( array( ‘taxonomy’ => ‘highlight’, ‘field’ => ‘slug’, ‘terms’ => array( ‘lead’,’featured’ ), ‘operator’ => ‘NOT IN’ ) ) ); $wpse42358_query = new WP_Query( $args ); while( $wpse42358_query->have_posts() ) : $wpse42358_query->the_post(); // write post stuff here … Read more

Custom Query Arguments

/** * Define a new function that uses $args and wp_parse_args() */ function explain_parse_args( $args ) { $defaults = array ( ‘text’ => ‘wp_parse_args() merges $args into $defaults’, ‘before’ => “”, ‘after’ => ” \n”, ‘echo’ => TRUE ); // Parse incomming $args into an array and merge it with $defaults $args = wp_parse_args( $args, … Read more

How to update WordPress custom SQL Select query for custom taxonomies so that syntax is correct?

You should not use a direct SQL query, instead try the WP_Query tax queries e.g.: $args = array( ‘post_type’ => ‘post’, ‘tax_query’ => array( ‘relation’ => ‘AND’, array( ‘taxonomy’ => ‘category’, ‘field’ => ‘id’, ‘terms’ => array( 22 ) ), array( ‘taxonomy’ => ‘job’, ‘field’ => ‘name’, ‘terms’ => $terms, ‘operator’ => ‘IN’ ) ) … Read more