pre_get_posts with WooCommerce Shortcode Query

You could use the WooCommerce filter woocommerce_shortcode_products_query to change/manipulate the query arguments. This example comes from the shortcode documentation. When using the Products shortcode, you can choose to order products by the pre-defined values above. You can also sort products by custom meta fields using the code below (in this example we order product by … Read more

Hide Add to Cart Button

Just add the following code in your functions.php and you will find button hidden I don’t know whether my solution is perfect. But it works. Normally if is_purchasable is returned to the filter woocommerce_is_purchasable, the ‘Add to Cart’ button is displayed, and if false is returned the button is hidden. So, you just need to … Read more

Shortcode with product catgory counter

Try this: (add it to the theme’s main functions.php file) add_shortcode( ‘products-counter’, ‘products_counter’ ); function products_counter( $atts ) { $atts = shortcode_atts( [ ‘category’ => ”, ], $atts ); $taxonomy = ‘product_cat’; if ( is_numeric( $atts[‘category’] ) ) { $cat = get_term( $atts[‘category’], $taxonomy ); } else { $cat = get_term_by( ‘slug’, $atts[‘category’], $taxonomy ); … Read more

WooCommerce lost password reset flow not working with SendGrid (redirect loop)

If you’re using SendGrid to process emails from WooCommerce and have click tracking enabled, links that use $_GET vars will break. Sendgrid uses a URL sanitizer that converts the &id= to &id= and that creates an issue in WooCommerce… The password reset form redirect looks for two get vars, $_GET[‘key’] and $_GET[‘id’], and if they’re … Read more

Query multiple post type and categories

The following code selects IDs of all posts type product and post, which belong to terms category-a or category-b, with taxonomy_01 and taxonomy_02, respectively. $args = [ ‘post_type’ => [‘product’,’post’], ‘posts_per_page’ => -1, ‘fields’ => ‘ids’, ‘tax_query’ => [ ‘relation’ => ‘OR’, [ ‘taxonomy’ => ‘taxonomy_01’, ‘field’ => ‘slug’, ‘terms’ => ‘category-a’, ‘include_children’ => false, … Read more

Display Categories Assigned to a WooCommerce Product

I have solved the issue with creating a list with http://codex.wordpress.org/Template_Tags/wp_list_categories changing style to list, then style it with CSS to my needs 🙂 <?php $taxonomy = ‘product_cat’; // get the term IDs assigned to post. $post_terms = wp_get_object_terms( $post->ID, $taxonomy, array( ‘fields’ => ‘ids’ ) ); if ( !empty( $post_terms ) && !is_wp_error( $post_terms … Read more