Image as Sales Badge

Change your image url to “/wp-content/uploads/2018/01/in-stock.png” That way even if you change servers (or changed domain name), as long as the filepath doesn’t change from wp-content, you’ll still be safe.

Woocommerce exclude specific categories products from related products

add_action( ‘wp’, ‘vn_remove_related_products’ ); function vn_remove_related_products() { if ( is_product() && has_term( array(‘workshops’, ‘events’), ‘product_cat’ ) ) { remove_action( ‘woocommerce_after_single_product_summary’, ‘woocommerce_output_related_products’, 20 ); } } Function has_term() can pass first parameter as array with terms.

WooCommerce Related Products by Attribute

Disable default Related Products and try this (Add custom code to the functions.php) add_action( ‘woocommerce_after_single_product_summary’, ‘custom_output_product_collection’, 12 ); function custom_output_product_collection(){ ## — YOUR SETTINGS — ## $attribute = “attribute_slug”; // <== HERE define your attribute slug $limit = “5”; // <== Number of products to be displayed $cols = “5”; // <== Number of columns … Read more

if statement for search results

Within the loop the best way to check if the result is a product would be to check the value of get_post_type(): if ( get_post_type() === ‘product’ ) { } As you say, is_woocommerce(), is_product() and is_search() are for checking which type of page is being viewed regardless of the current item in the loop.

WooCommerce shop page orderby [closed]

WooCommerce have moved this setting to the WordPress Customizer. From your WordPress admin area, browse to: Appearance -> Customise Then, from within the customiser, you can find the setting here: WooCommerce -> Product Catalogue and simply change the order under the option ‘Default Product Sorting’

WC displaying products from category

For custom taxonomies, including Product Categories, you should use the tax_query argument: $args = array( ‘post_type’ => ‘product’, ‘posts_per_page’ => 12, ‘tax_query’ => array( array( ‘taxonomy’ => ‘product_cat’, ‘terms’ => 40, ), ), );