variations

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)

Custom display based on Woocommerce product variations stock data checkbox option

丶灬走出姿态 提交于 2020-07-22 06:12:22
问题 I am trying to add a custom message to variation products, based on their stock quantity and stock status. So far i got this: function load_variation_settings_fields( $variation_data, $product, $variation ) { // Display shipping delay text when stock quantity exist if( $variation->get_stock_quantity() > 0 ) $variation_data['text_field'] = __('<p class="stock in-stock">Stock: <span>På lager</span><br>Delivery: <span>2-12 hverdage</span></p>'); else $variation_data['text_field'] = __('<p class=

Get the selected variation attributes from orders in Woocommerce 3

非 Y 不嫁゛ 提交于 2020-06-12 07:27:49
问题 In Woocommerce, I have a report in the admin area that tallies up products sold.There are only 5 products sold on the site but there are 1 or 2 variations on some. The report works great but ignores the variations. I need to retrieve the attribute value from items ordered to display the data accurately. How do I do this? get_variation_description() is not working the way I'm applying it. My code: $order = wc_get_order( $vs); //BEGIN NEW RETRIEVE ORDER ITEMS FROM ORDER foreach( $order->get

Adding custom text to the variation price in Woocommerce

二次信任 提交于 2020-03-23 10:58:07
问题 I thought this would have been easy, but I am stuck. All I am trying to do is add the word each after the variation price on a product page. The solution I have found adds it on the category page and in two places on the product page. The code is: /* Adds a text Each - after price */ function change_product_price( $price ) { $price .= ' each'; return $price; } add_filter( 'woocommerce_get_price_html', 'change_product_price' ); From the picture above, I only need the each added to the price

code management: generate source files with slight variations of various rules

别来无恙 提交于 2020-01-26 03:33:09
问题 I have a source file in a declarative language ( twolc , actually) that I need to write many variations on: a normative version and many non-normative versions, each with one or more variations from the norm. For example, say the normative file has three rules: Rule A: Do something A-ish Rule B: Do something B-ish Rule C: Do something C-ish Then one variation might have the exact same rules as the norm for A and C , but a different rule for B , which I will call B-1 : Rule A: Do something A

Add backorders stock status to Woocommerce variable product dropdown

久未见 提交于 2020-01-24 11:15:48
问题 I would like to show the stock status of variable products in the dropdown menu, including 'on backorder' as most products on my site are available on backorder rather than being 'out of stock'. I have tried the answer from How to add variation stock status to Woocommerce product variation dropdown however, every variable is listed as 'in stock' because the product is set to allow backorders. I would like to incorporate checking the actual stock levels like below, but I can't get it to work

Add backorders stock status to Woocommerce variable product dropdown

岁酱吖の 提交于 2020-01-24 11:15:22
问题 I would like to show the stock status of variable products in the dropdown menu, including 'on backorder' as most products on my site are available on backorder rather than being 'out of stock'. I have tried the answer from How to add variation stock status to Woocommerce product variation dropdown however, every variable is listed as 'in stock' because the product is set to allow backorders. I would like to incorporate checking the actual stock levels like below, but I can't get it to work

Show stock status next to each attribute value in WooCommerce variable products

天涯浪子 提交于 2020-01-19 06:08:14
问题 I want to implement in my store something similar like this: I have this code, but this show quantity next to each variation. function get_stock_variations_from_product(){ global $product; $variations = $product->get_available_variations(); foreach($variations as $variation){ $variation_id = $variation['variation_id']; $variation_obj = new WC_Product_variation($variation_id); $stock = $variation_obj->get_stock_quantity(); } } And also this code: global $product; $product_variations = $product

Check if a product variation is in cart in Woocommerce

♀尐吖头ヾ 提交于 2020-01-15 06:00:32
问题 I am trying display if a variation of a product is already in a cart or not (in single product page). A simple comparing of the product id with products in cart object is not working for variable product as the variation id is being loaded using ajax. Here is my code that works in case the product type is other than variable. <?php /* * Check if Product Already In Cart */ function woo_in_cart( $product_id ) { global $woocommerce; if ( !isset($product_id) ) { return false; } foreach(