categories

WooCommerce get category slug - Undefined property notice with a function

我只是一个虾纸丫 提交于 2020-08-19 12:58:07
问题 I use this function to convert the woocommerce category id into a category slug function woocommerceCategorySlug($id){ $term = get_term( $id, 'product_cat' ); return $term->slug; } This is working, but the problem is that i'm getting a notice Notice: Undefined property: WP_Error::$slug Is there a way to avoid this notice? 回答1: The working solution for this is to use WordPress native function get_term_by() and to transpose it in your code this way: function woocommerceCategorySlug( $id ){

Hide Price based on product category in Woocommerce

二次信任 提交于 2020-08-07 07:15:49
问题 In Woocommerce I am trying to hide the product on the archive page and single product page based on category however the condition does not appear to work and just hide all the price whether I set the category or not add_filter( 'woocommerce_variable_sale_price_html', 'woocommerce_remove_prices', 10, 2 ); add_filter( 'woocommerce_variable_price_html', 'woocommerce_remove_prices', 10, 2 ); add_filter( 'woocommerce_get_price_html', 'woocommerce_remove_prices', 10, 2 ); function woocommerce

Hide Price based on product category in Woocommerce

蓝咒 提交于 2020-08-07 07:15:42
问题 In Woocommerce I am trying to hide the product on the archive page and single product page based on category however the condition does not appear to work and just hide all the price whether I set the category or not add_filter( 'woocommerce_variable_sale_price_html', 'woocommerce_remove_prices', 10, 2 ); add_filter( 'woocommerce_variable_price_html', 'woocommerce_remove_prices', 10, 2 ); add_filter( 'woocommerce_get_price_html', 'woocommerce_remove_prices', 10, 2 ); function woocommerce