custom-taxonomy

Add a new term to a product attribute and set it in the product in Woocommerce

时光怂恿深爱的人放手 提交于 2019-11-28 09:24:34
问题 My custom taxonomy (WooCommerce attribute) already exists and I am using the following to add a new term to the taxonomy and associate it with my WooCommerce product: wp_set_object_terms($product_id, array($omega_jahr), 'pa_years-of-construction'); When I use the following to call the 'pa_years_of_construction' for my product, I can see that the new terms have been saved: $v = array_values( wc_get_product_terms( $product->id, 'pa_years-of-construction', array( 'fields' => 'names' ) ) );

Get custom product attributes in Woocommerce

只谈情不闲聊 提交于 2019-11-26 22:07:38
In Woocommerce, I am trying to get product custom attribute values but I fail miserably and I don't get anything. So I tried: global $woocommerce, $post, $product; $res = get_post_meta($product->id); print_r(unserialize($res['_product_attributes'][0])); And I'm getting this raw data: [pa_koostis] => Array ( [name] => pa_koostis [value] => [position] => 0 [is_visible] => 1 [is_variation] => 0 [is_taxonomy] => 1 ) I know that there is a value because it is shown in the attribute section, but I just can't find a way to get it displayed with my custom code. Nick Edited : The woocommerce_get

Create new product attribute programmatically in Woocommerce

非 Y 不嫁゛ 提交于 2019-11-26 20:50:26
How can I create attributes for WooCommerce from a plugin? I find only : wp_set_object_terms( $object_id, $terms, $taxonomy, $append); From this stack-question But this approach required id of some product. I need to generate some attributes not attached to any products. helgatheviking To create a term you can use wp_insert_term() like so: wp_insert_term( 'red', 'pa_colors' ); where colors is the name of your attribute. The taxonomy name of an attribute is always prepended by pa_ . Edit Attributes are merely custom taxonomies. Or you could say they are dynamic taxonomies that are manually

Get custom product attributes in Woocommerce

折月煮酒 提交于 2019-11-26 08:09:15
问题 In Woocommerce, I am trying to get product custom attribute values but I fail miserably and I don\'t get anything. So I tried: global $woocommerce, $post, $product; $res = get_post_meta($product->id); print_r(unserialize($res[\'_product_attributes\'][0])); And I\'m getting this raw data: [pa_koostis] => Array ( [name] => pa_koostis [value] => [position] => 0 [is_visible] => 1 [is_variation] => 0 [is_taxonomy] => 1 ) I know that there is a value because it is shown in the attribute section,

Create new product attribute programmatically in Woocommerce

馋奶兔 提交于 2019-11-26 07:44:54
问题 How can I create attributes for WooCommerce from a plugin? I find only : wp_set_object_terms( $object_id, $terms, $taxonomy, $append); From this stack-question But this approach required id of some product. I need to generate some attributes not attached to any products. 回答1: To create a term you can use wp_insert_term() like so: wp_insert_term( 'red', 'pa_colors' ); where colors is the name of your attribute. The taxonomy name of an attribute is always prepended by pa_ . Edit Attributes are