custom-taxonomy

Display specific product attributes on Woocommerce archives pages

a 夏天 提交于 2020-06-24 14:01:44
问题 I want to display some specific product attributes of my choice on the store shop page for each product. It is necessary to display the name of the attribute and opposite its value. I started writing code, I wanted to print at least names, but I only show the name of the last attribute add_action('woocommerce_after_shop_loop_item','add_attribute'); function add_attribute() { global $product; $weigth_val = $product->get_attribute('weight'); $quant_val = $product->get_attribute('quantity');

Display specific product attributes on Woocommerce archives pages

只愿长相守 提交于 2020-06-24 14:01:07
问题 I want to display some specific product attributes of my choice on the store shop page for each product. It is necessary to display the name of the attribute and opposite its value. I started writing code, I wanted to print at least names, but I only show the name of the last attribute add_action('woocommerce_after_shop_loop_item','add_attribute'); function add_attribute() { global $product; $weigth_val = $product->get_attribute('weight'); $quant_val = $product->get_attribute('quantity');

How to check if product has a specific product attribute in Woocommerce

不羁岁月 提交于 2020-06-12 04:13:12
问题 I would like to identify if a product has an attribute or not. For example: if (product has attribute 'pa_color') { //do something } How can I accomplish this? 回答1: You simply can use the WC_Product method get_attribute() this way: // (If needed) Get an instance of the WC_Product Object from the product ID $product = wc_get_product( $product_id ); // Get the product attribute value(s) $color = $product->get_attribute('pa_color'); // if product has attribute 'pa_color' value(s) if( ! empty(

How to check if product has a specific product attribute in Woocommerce

强颜欢笑 提交于 2020-06-12 04:13:10
问题 I would like to identify if a product has an attribute or not. For example: if (product has attribute 'pa_color') { //do something } How can I accomplish this? 回答1: You simply can use the WC_Product method get_attribute() this way: // (If needed) Get an instance of the WC_Product Object from the product ID $product = wc_get_product( $product_id ); // Get the product attribute value(s) $color = $product->get_attribute('pa_color'); // if product has attribute 'pa_color' value(s) if( ! empty(

Avoid add to cart for specific product categories if user is unlogged in Woocommerce

泄露秘密 提交于 2020-04-16 04:09:45
问题 In Woocommerce, I am trying to disable specific product categories to be added to the cart for users that aren't logged in. i'm looking for a solution the last couple of days and after frustrated deleting the last code I found this but also doesn't do the job. I'm using a certain plugin (TZ product tabs) to show products on other pages (so not only on the category and product page (this i know how to disable)) add_action( 'woocommerce_after_shop_loop_item', 'remove_add_to_cart_buttons', 1 );

Get the Product tags for the current product only in WooCommerce

故事扮演 提交于 2020-02-22 07:58:21
问题 How can I display only the product tags for the current single product page and not all the products tags? I've found questions about most popular tags but not for that. 回答1: You can use the function wp_get_post_terms() function for WooCommerce 'product_tag' custom taxonomy and a defined product id this way: $output = array(); // get an array of the WP_Term objects for a defined product ID $terms = wp_get_post_terms( get_the_id(), 'product_tag' ); // Loop through each product tag for the

Get the id of a WooCommerce category, by name

天涯浪子 提交于 2020-02-03 08:52:27
问题 I have a wp template that I would like to assign to some pages. The template would ie. display all WooCommerce products that have the same master category name as the pages name itself. By far I have tried using this code, but with no good output: $idObj = get_category_by_slug($pagename); $id = $idObj->term_id; echo ": ". $id; Unfortunately, the echo does not display anything. Echoing $pagename works, and returns me the slug of the page. Any good way I could make this work? 回答1: With a custom

Show WooCommerce product attributes in custom home and product category archives

主宰稳场 提交于 2020-01-24 12:30:13
问题 The below code that displays product attributes on product category archive pages and is based on "Display product attributes on specific Woocommerce product category archives page" answer thread. However, when I add that category on the homepage, It does not display the attributes. My code version: // Show Attributes on Product Category Page add_action('woocommerce_after_shop_loop_item','display_loop_product_attribute' ); function display_loop_product_attribute() { global $product; //

Add a filter dropdown for product tags in woocommerce admin product list

你离开我真会死。 提交于 2020-01-21 14:55:13
问题 I want to also add a filter tag next to the filter by category in the woocommerce products page. Below image is in ducth but I want to add another dropdown menu if possible. 回答1: Try the following that will add filtering for product tags in admin product list: add_action('restrict_manage_posts', 'product_tags_sorting'); function product_tags_sorting() { global $typenow; $taxonomy = 'product_tag'; if ( $typenow == 'product' ) { $selected = isset($_GET[$taxonomy]) ? $_GET[$taxonomy] : ''; $info

wordpress get taxonomy list of custom post type

时光怂恿深爱的人放手 提交于 2020-01-14 12:36:13
问题 I am using "Video" theme for my wordpress website. In this theme, videos post type and "videoscategory" taxonomy are defined. Here is the register code for taxonomy: add_action("init", "custom_posttype_menu_wp_admin1"); function custom_posttype_menu_wp_admin1() { register_post_type('videos', array('label' => __('Videos','templatic'), 'labels' => array( 'name' => __('Video','templatic'), 'singular_name' => __('Video','templatic'), 'add_new' => __('Add Video','templatic'), 'add_new_item'=> __(