custom-taxonomy

Creating WooCommerce product variation adds an empty attribute value

北城余情 提交于 2020-08-09 08:24:30
问题 When adding variations to a WooCommerce product it is adding in a blank attribute. Meaning that when I try to add in my own attribute it gets appended to an existing array. Example code I am running: $product_variation = wc_get_product( $variation_id ); $product_variation->set_attributes(array('attribute_pa_varinfo' => 'blue')); $product_variation->save(); Then when I var_dump($product_variation); I get the following: ["attributes"]=> array(2) { [0]=> string(0) "" ["pa_varinfo"]=> string(4)

Creating WooCommerce product variation adds an empty attribute value

拟墨画扇 提交于 2020-08-09 08:24:25
问题 When adding variations to a WooCommerce product it is adding in a blank attribute. Meaning that when I try to add in my own attribute it gets appended to an existing array. Example code I am running: $product_variation = wc_get_product( $variation_id ); $product_variation->set_attributes(array('attribute_pa_varinfo' => 'blue')); $product_variation->save(); Then when I var_dump($product_variation); I get the following: ["attributes"]=> array(2) { [0]=> string(0) "" ["pa_varinfo"]=> string(4)

Exclude a product category from the loop in Woocommerce

跟風遠走 提交于 2020-07-30 10:19:07
问题 I'd like to exclude the category of my current post from the loop. Pretty easy usually, this time it doesn't work and I can't figure out what's wrong here. Here's my page'code: $postid = get_the_ID(); // curret product ID <section class="related products"> <?php $args = array( 'post__not_in' => array($postid), // Exclude displayed product 'post_type' => 'product', 'post_status' => 'publish', 'posts_per_page' => '6', 'cat' => '-33' // Exclude cat ); $related_products = new WP_Query($args); ?>

How to get the brand name of product in WooCommerce

坚强是说给别人听的谎言 提交于 2020-07-18 08:32:26
问题 i need get the brand name of product , i have this code $product = wc_get_product(); $type = $product->get_type(); $name = (string)$product->get_name(); $id = (int)$product->get_id(); $sku = (int)$product->get_sku(); $precio = (int)$product->get_price(); $brand_name = $product->get_brand(); ---> ??? i get this attributes but i don't know how catch the brand name, is there another way ? Thanks! 回答1: Use get_the_terms get_the_terms($product->get_id(),'pa_brand') 回答2: Is better to use wc_get

Products dropdown from same category inside Woocommerce product short description

与世无争的帅哥 提交于 2020-07-03 09:56:50
问题 In Woocommerce, I would like to add a drop down in product short description that shows all products that have the same category(ies). It will be even better if it was possible to go to the product page of the selected product. I didn't see any threads that fulfill what I am trying to do. Any help will be appreciated. 回答1: 2020 Update 4 - Added product_id as argument, allowing the shortcode to be used for a defined product ID (for example on a page). The following will make a custom shortcode

Display Variable Product Attributes and Terms on Woocommerce Archives

ⅰ亾dé卋堺 提交于 2020-07-03 08:56:35
问题 I am trying to accomplish a attribute and term list on the shop page using the hook woocommerce_shop_loop_item_title . The goal is to get the attribute(s) and term(s) for the product and then to display it like this example: Color: Red, Blue, Green Size: Small, Medium, Large Dimensions: 90*90, 100*100 and 120*120 but without the spaces between the rows. It should "fetch" all the attributes used with the product and the attributes terms. I've tried this but got fatal error. add_action(

Display Variable Product Attributes and Terms on Woocommerce Archives

守給你的承諾、 提交于 2020-07-03 08:51:51
问题 I am trying to accomplish a attribute and term list on the shop page using the hook woocommerce_shop_loop_item_title . The goal is to get the attribute(s) and term(s) for the product and then to display it like this example: Color: Red, Blue, Green Size: Small, Medium, Large Dimensions: 90*90, 100*100 and 120*120 but without the spaces between the rows. It should "fetch" all the attributes used with the product and the attributes terms. I've tried this but got fatal error. add_action(

Hide shipping methods based on products categories in Woocommerce

人走茶凉 提交于 2020-06-26 14:13:52
问题 With Woocommerce, I would like to hide all shipping methods except "Local pickup" when a defined products category is in cart… The code below does that for other product types, except variable products: add_filter( 'woocommerce_package_rates', 'custom_shipping_methods', 100, 2 ); function custom_shipping_methods( $rates, $package ){ // Define/replace here your correct category slug (!) $cat_slug = 'my_category_slug'; $prod_cat = false; // Going through each item in cart to see if there is

Exclude specific product categories on Woocommerce single product pages

空扰寡人 提交于 2020-06-26 06:51:13
问题 I'm trying to exclude some categories from being displayed on the WooCommerce product page. Example : if in a single product page I have "Categories: Cat1, Cat"2", I want that only Cat1 will be displayed. I tried editing the meta.php in the single-product template. I created a new function: $categories = $product->get_category_ids(); $categoriesToRemove = array(53,76,77,78); // my ids to exclude foreach ( $categoriesToRemove as $categoryKey => $category) { if (($key = array_search($category,