Manage Woocommerce stock variations for multiple products
Ideally I would like to know if anyone knows a plugin that can do what I need, but if it needs code, I can probably work with it.
So I'm making a Woocommerce shop of handmade clothing and there are multiple products that are made of multiple fabrics. I need one place where I can enter in the total amount of fabric and that will manage the stock for all the products.
Example: The shop offers 3 styles of skirts in 3 different fabrics. There is enough black fabric for 10 skirts so the quantity of each skirt in black is 10. A customer orders skirt #1 in black, so the stock for skirts #1, #2 and #3 in black all need to change to 9 in stock.
Is this possible? I really appreciate any help. Thanks!
See also questions close to this topic
-
How to show total price of items in Woocommerce
I am using Display number of items sold between dates with a shortcode in WooCommerce answer code which displays the number of items sold in a period. This works like a charm.
But I also want to display the total price of these items. so I've just changed in the code the meta key
_qty
to_price
but that didn't work.It's probably something small Any help or hint is appreciated?
-
show attributes at compare page woocommerce
I have a woocommerce shop. I want to have a compare page and all the attributes of each products to be shown. there is a shortcode of [irk-compare-table] that should put in the page I want to show compare list. everything is ok but there only shows some of the attributes and not all the attributes of each product. how can I show other attributes. I even used woocommerce compare plugin, It shows the attributes title but no values within it. how I can have other attributes on the compare page? there is a function irk_get_compare_list(), maybe I can use from that. the question is how can show all the attributes in compare page and why not all attributes are shown?
-
Add custom my account menu item based on user role in WooCommerce 3+
I am using WordPress and WooCommerce and I have followed this article https://rudrastyh.com/woocommerce/my-account-menu.html to add new menu items in WooCommerce my account menus.
This is my working code.
function getUserRolesByUserId( $id ) { if ( !is_user_logged_in() ) { return false; } $oUser = get_user_by( 'id', $id ); $aUser = get_object_vars( $oUser ); $sRoles = $aUser['roles']; return $sRoles; } function createMenuBasedonUserRole($userId) { $userRoleIds = getUserRolesByUserId(get_current_user_id()); $urlMenuData = []; if(!empty($userRoleIds) && in_array('mindesk_var_account',$userRoleIds)) { $urlMenuData = [ 'pageName' => "Clients", "pageLink" => "clients" ]; } else if(!empty($userRoleIds) && in_array('mindesk_owner_account',$userRoleIds)) { $urlMenuData = [ 'pageName' => "Children", "pageLink" => "children" ]; } return $urlMenuData; } /* * Step 1. Add Link (Tab) to My Account menu */ add_filter ( 'woocommerce_account_menu_items', 'mindesk_clients_children_link', 40 ); function mindesk_clients_children_link( $menu_links ){ $urlData = createMenuBasedonUserRole(get_current_user_id()); if(!empty($urlData)){ $menu_links = array_slice( $menu_links, 0, 5, true ) + array( $urlData['pageLink'] => $urlData['pageName'] ) + array_slice( $menu_links, 5, NULL, true ); } return $menu_links; } /* * Step 2. Register Permalink Endpoint */ add_action( 'init', 'mindesk_add_menu_endpoint' ); function mindesk_add_menu_endpoint() { add_rewrite_endpoint( 'clients', EP_PAGES ); add_rewrite_endpoint( 'children', EP_PAGES ); } /* * Step 3. Content for the new page in My Account, woocommerce_account_{ENDPOINT NAME}_endpoint */ add_action( 'woocommerce_account_clients_endpoint', 'mindesk_clients_my_account_endpoint_content' ); function mindesk_clients_my_account_endpoint_content() { require_once(get_template_directory() . '/myaccount/clients.php') ; } add_action( 'woocommerce_account_children_endpoint', 'mindesk_children_my_account_endpoint_content' ); function mindesk_children_my_account_endpoint_content() { require_once(get_template_directory() . '/myaccount/children.php') ; } /* Step 4 */ // Go to Settings > Permalinks and just push "Save Changes" button.
And this is my how my new menu called as "Clients" showing.
As you can see above, I have added new menu and executing the page and based on user role
mindesk_var_account
I need to showclients
andmindesk_owner_account
I need to showchildren
.I have created these 2 php pages at
/wp-content/themes/twentytwentyone/myaccount
and its working fine.However, I want to use
wp_die
or something if user with another role try to access one of the page which they are not allowed to.So for example if logged in user has
mindesk_var_account
role then if they try to go to http://localhost/wordpress/my-account/clients/ then i need to usewp_die()
to not execute it.I tried to use
wp_die
inside these new 2 pages but then menus and other things executed. I just want something like this.I tried to use following code...
add_action( 'template_redirect', 'my_account_redirect' ); function my_account_redirect() { if( is_page( 'my-account' ) ) { wp_die('fg'); } }
But then its checking for all
my-account
pages .. and I want it to be checked only for inner pages likeclient
orchildren
.Can someone guide me how can I achieve this what should I do from here on.
Thanks
-
Hide product attribute on all pages and popups quick overviews
I am looking for a way to hide certain product-attributes on all pages, not only the product page. This is because I am working with elementor and buidling my own product templates.
I am using: Hide specific product attribute dropdown on WooCommerce variable products answer code, where I replaced for my usage:
$product->get_attribute('Brand')
with:
$product->get_attribute('alt_omschrijving')
This works fine for the product-pages but the attribute is still visible on the Quick Overview and in my custom designed product template. Any idea to alter the code so the attribute is hidden for all elements on my site?
-
Collect Attribute values and display it in the DOM whit JavaScript
I am developing a website that contains a series of products, each block contains a certain product, when hovering the mouse I need the name of this product to appear,
However, the product name is stored through an 'DATA' attribute. for example:
data-legend-item = "White T-Shirt"
I need to collect the value of this data attribute and make it appear every time I hover over it.
Remembering that they are a collection of blocks so I need to collect them from all data-legend-items on the page.
ps: notice that I made a script that only collects this value only from the first blockthat contains a data-legend-item
[
function dataTitleProduct(productItem) { // collecting data-legend-item main attribute var productItem = document.getElementById('item-title').getAttribute("data-legend-item"); // pulling the value of the data-legend-item attribute and inserting it in the html document.querySelector('[data-legend-item]').innerHTML = productItem; } dataTitleProduct();
.products { /* Div pai*/ max-width: 320px; width: 100%; } /* Filhos recebendo distanciamento de 5 margin*/ .products .product-view { margin: 5px auto; } /* */ .products .product-view { max-width: 200px; display: flex; flex-flow: column wrap; text-align: center; margin: 0 auto; } .product-view .product { height: 150px; background-color: #ffffff; box-shadow: 0 1px 3px #c7c7c7; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; transition: all .3s ease; position: relative; } .product-view .product:hover { box-shadow: 0 7px 7px rgba(90, 90, 90, 0.2); cursor: pointer; content: ''; } /* Titulo do Produto*/ .product-view .product [data-legend-item] { display: block; line-height: 220px; position: relative; font-size: 1.1rem; color: #ffffff; z-index: 1; } .product-view .product [data-legend-item]:before { width: 100%; height: 40px; background-color: rgba(0, 0, 0, 0.5); position: absolute; top: 90px; left: 0; right: 0; bottom: 0; z-index: -1; content: ''; }
<div class="products"> <div class="product-view"> <div id="item" class="product"> <div id="item-title" data-legend-item="T-shirt White"></div> </div> </div> <div class="product-view"> <div id="item" class="product"> <div id="item-title" data-legend-item="Shoes"></div> </div> </div> <div class="product-view"> <div id="item" class="product"> <div id="item-title" data-legend-item="Black T-shirt"></div> </div> </div> </div>
]1
-
Get attribute from element in XML-file using Powershell
I have this xml-file:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:foo="http://schemas.foo.com/bar/baz/qux" foo:code="220" > <Bar>Baz</Bar> </manifest>
Notice the attribute
foo:code="220"
with its namespacexmlns:foo="http://schemas.foo.com/bar/baz/qux"
.I'm trying to get the attribute's value in a Powershell script.
I have already a C# implementation which I'm trying to port to Powershell. Here is the C#-implementation.
using System; using System.Xml.Linq; static void Main(string[] args) { var xmlFile = XDocument.Load(@"C:\File\Path\To\File.xml"); var manifest = xmlFile.Element("manifest"); var code = manifest.Attribute(XName.Get("code", "http://schemas.foo.com/bar/baz/qux")); }
Here is what I have tried in Powershell.
using namespace System using namespace System.Xml.Linq $xmlFile = [XDocument]::Load("C:\File\Path\To\File.xml") $manifest = $xmlFile.Element("manifest") $f = [XName]::Get("code", "http://schemas.foo.com/bar/baz/qux") # Works $g = $manifest.Attribute($f) # Nothing (null) $code = $manifest.Attribute([XName]::Get("code", "http://schemas.foo.com/bar/baz/qux")) # Nothing (null)
As demonstrated the code to get the attribute don't work in Powershell.
Is there a solution to this?
-
How can I make WooCommerce Product Price in Category Page clickable?
On any product archive / category page I'd like to be able to click on the product price and have it take me to that products page just like clicking on the product image or title does by default. This is because I've used CSS to make the price look more like a button, here's an example.
This website is using the Astra Pro theme and WooCommerce.
-
Details of Google product calculator
I tried to use the product calculator
https://cloud.google.com/products/calculator/#id=f5b35a8e-b8a3-4412-a9f3-af00bfb113c6
and got a result of $67.91 in Cloud SQL
Does anyone know how this result comes up? because if I refer to this page
https://cloud.google.com/sql/pricing
it should be $52.28
=================
db-g1-small, $0.0455 > 8/5 hour (160h/month) > $0.0455 x 160 = $7.28
$0.090 per GB/month for HDD storage capacity > 500gb/month > $0.090 x 500 = $45
The grand total will be $52.28
-
Grey out Woocommerce sold out variation, but leave clickable
I would like to grey out my sold out variations. However I would like to leave these clickable. I know we can grey them out and disable the click... but this is not what I need.
Is there a way with this could be achieved at all? The reason I would like to leave clickable is so I can have a back in stock notifier, on the styles that are sold out.
Thanks,
-
set 6m in zoom panel for user in stock chart
would you plz tell me how can I set the zoom in 6m in the stock chart that I make with am chart? by default is set in max when the user opens a page and sees the chart without choosing any button in the zoom panel. https://www.amcharts.com/demos/stock-chart/ I use this demo
I use that code in the link above
- removing regression stock tool indicator shifts the graph upwards (highcharts)
-
Stock Chart Patterns
Stock chart patterns can be a vital tool for investors. They provide an exceptionally detailed level of a stock’s trend lines. This can give a major leg up against the competition. This is why they are used by the likes of retail investors, billion-dollar hedge funds and everyone in between.Basically, best trading patterns platform are a way to view the ups and downs of a stock’s price over the course of time… and then use that information to help predict future movement. They can be a micro-analysis of a single day’s worth of trading. Or they can offer a long-term view of a stock’s performance over the course of several years. iron condor tend to repeat themselves over and over again. So when investor’s see them forming, they can get a better idea of which direction a stock’s price may be heading.
How the Ascending Triangle Pattern Works
You’ve likely heard somebody say the phrase, “I just happened to be in the right place at the right time.” Stock trading is no different, it’s all about being in the right position at the right time. This is the reason why the ascending triangle pattern is a favorite among many stock traders. For those who understand this chart pattern and trade it correctly, it’s a trading strategy that can result in big profits. It is one of the three important triangle patterns defined by classical technical analysis. The other two being the descending triangle and the symmetrical triangle. The ascending triangle is a continuation pattern defined by an entry point, stop loss, and profit target. On the price chart, it appears as a horizontal support line connecting the highs to an upward moving trendline to the lows. Each ascending triangle has a minimum of two highs and two lows. In comparison, a descending triangle has a horizontal lower line and a descending upper trendline. The above chart is a representation of an ascending triangle. It consists of a horizontal resistance line drawn across the minor highs with a rising trend line connecting the minor lows, which form a triangular pattern. Ascending triangles are continuation patterns because the price usually breaks in the direction it was going before the pattern. As with other types of triangles, the volume often contracts during the charts pattern. Keeping an eye on false breakouts, investors usually enter when the price breakout takes place. The position they take depends on the direction of the breakout – buy for upside direction and sell for downside direction. The stop loss is placed just outside the triangle. To calculate the profit target, traders take into account triangle height at maximum width and adjust that measurement according to the breakout price.
-
Batch delete existing variation from products (wordpress woocommerce)
how can I remove attributes from products on my web site in bulk?
I'll leave a few images as an example.
Although I delete 1 variation of my products with 3 variations from the attributes, it appears on the product page.
-
Woocommerce - Product Variation Preorder price
Im kinda new to woocommerce dev and haven't developped in PHP for ages.
With the help of @LoicTheAztec, I implemented Preording on my Woocommerce store using this :
// Admin Variation custom fields add_action( 'woocommerce_product_after_variable_attributes', 'ab_preorder_variation_fields', 10, 3 ); function ab_preorder_variation_fields( $loop, $variation_data, $variation ) { echo '<div class="options_group form-row form-row-full">'; // Is Preordable woocommerce_wp_checkbox( array( 'id' => '_ab_preorder_checkbox['.$loop.']', 'wrapper_class' => 'show_if_simple', 'label' => __(' Disponible à la précommande', 'woocommerce' ), 'description' => __( 'Disponible à la précommande', 'woocommerce' ), 'desc_tip' => true, 'value' => get_post_meta( $variation->ID, '_ab_preorder_checkbox', true ) ) ); // Custom Preorder Price woocommerce_wp_text_input( array( 'id' => '_ab_preorder_custom_price['.$loop.']', 'label' => __( 'Prix à la précommande', 'woocommerce' ), 'placeholder' => '', 'desc_tip' => true, 'description' => __( "Prix à la précommande", 'woocommerce' ), 'type' => 'number', 'custom_attributes' => array( 'step' => 'any', 'min' => '0' ), 'value' => get_post_meta( $variation->ID, '_ab_preorder_custom_price', true ) ) ); // Date de livraison estimée woocommerce_wp_text_input( array( 'id' => '_ab_preorder_estimated_date['.$loop.']', 'label' => __( 'Date de livraison estimé', 'woocommerce' ), 'desc_tip' => true, 'description' => __( "Date de livraison estimé", "woocommerce" ), 'type' => 'date', 'value' => get_post_meta( $variation->ID, '_ab_preorder_estimated_date', true ) ) ); echo '</div>'; } // Save admin Variations custom fields values add_action( 'woocommerce_admin_process_variation_object', 'ab_preorder_variation_fields_saving', 10, 2 ); function ab_preorder_variation_fields_saving( $variation, $loop ) { if( isset($_POST['_ab_preorder_checkbox'][$loop]) ) { $variation->update_meta_data( '_ab_preorder_checkbox', esc_attr($_POST['_ab_preorder_checkbox'][$loop]) ); } if( isset($_POST['_ab_preorder_custom_price'][$loop]) ) { $variation->update_meta_data( '_ab_preorder_custom_price', esc_attr($_POST['_ab_preorder_custom_price'][$loop]) ); } if( isset($_POST['_ab_preorder_estimated_date'][$loop]) ) { $variation->update_meta_data( '_ab_preorder_estimated_date', esc_attr($_POST['_ab_preorder_estimated_date'][$loop]) ); } } // Set the variation backorder price add_filter('woocommerce_product_variation_get_regular_price', 'custom_price', 99, 2 ); add_filter('woocommerce_product_variation_get_price', 'custom_price', 99, 2 ); function custom_price( $price, $product ) { if ( $product->get_stock_quantity() == 0 && $product->get_meta('_ab_preorder_checkbox') === 'yes' ) { $backorder_price = $product->get_meta('_ab_preorder_custom_price'); if( $backorder_price > 0 ) { $price = (float) $backorder_price; } } return $price; } // Display prefixed backorder price and estimated delivery on single product pages add_filter( 'woocommerce_available_variation', 'ab_available_variation_custom_field', 10, 3 ); function ab_available_variation_custom_field( $variation_data, $product, $variation ) { if ( $variation->get_stock_quantity() == 0 && $variation->get_meta('_ab_preorder_checkbox') === 'yes' ) { if ( $estimated_delivery_date = $variation->get_meta('_ab_preorder_estimated_date') ) { // Display estimated delivery date $variation_data['availability_html'] .= sprintf( '<p class="stock date-precommande">%s : %s</p>', __("Date de livraison estimée (précommande)", "woocommerce"), $estimated_delivery_date ); } // Displayed prefixed formatted price $variation_data['price_html'] = '<span class="price-prefix">'.__("Prix à la précommande", "") .'<span> : ' . wc_price( $variation_data['display_price'] ); } return $variation_data; } // Display on estimated delivery date on cart and checkout add_filter( 'woocommerce_get_item_data', 'display_acf_on_cart_and_checkout', 10, 2 ); function display_acf_on_cart_and_checkout( $cart_data, $cart_item ) { if ( $cart_item['variation_id'] > 0 && $cart_item['data']->get_stock_quantity() == 0 && $cart_item['data']->get_meta('_ab_preorder_checkbox') === 'yes' ) { if ( $estimated_delivery_date = $cart_item['data']->get_meta('_ab_preorder_estimated_date') ) { $custom_items[] = array( "name" => __("Date de livraison estimée", "woocommerce"), "value" => $estimated_delivery_date ); } } return $custom_items; }
So i added custom fields in Product Variation configuration :
When i want to allow preordering on a product, i just need to check the
_ab_preorder_checkbox
(Disponible à la précommande) checkbox and enter a_ab_preorder_custom_price
and an estimated delivery date_ab_preorder_estimated_date
.Everything works good, the problem im facing is : When i have only one copy left from a product and the client tries to order more than just one (2-3), the product gets added to the cart with the original price and not with the preorder discount.
The behavior i want to have is : When i have
X
copies left of a product and the client decides to orderX+Y
copies, i want to set the original price for theX
copies and the preorder price_ab_preorder_custom_price
for theY
copies.I tought about using the
woocommerce_before_calculate_totals
hook but im not sure about how to implement that and i don't know if the best solution.Here's what i did so far (and it's not working) :
add_filter( 'woocommerce_before_calculate_totals', 'filter_woocommerce_add_to_cart_validation', 1000, 1 ); function filter_woocommerce_add_to_cart_validation( $cart) { if ( did_action( 'woocommerce_before_calculate_totals' ) >= 2 ) return; foreach ( $cart->get_cart() as $cart_item_key => $cart_item ) { if ( $cart_item['data']->get_meta('_ab_preorder_checkbox') === 'yes' && $cart_item['data']->get_stock_quantity() < $cart_item['quantity'] ){ $cart->set_quantity($cart_item_key, $cart_item['data']->get_stock_quantity()); $new_cart_item = $cart_item; $new_cart_item['data']->set_price(5); $new_cart_item['regular_price'] = 5; $new_cart_item['key'] = md5( microtime().rand() ); $variation = new WC_Product_Variation($new_cart_item['variation_id']); $variation_data = $variation->get_variation_attributes(); $cart->add_to_cart($new_cart_item['product_id'], $new_cart_item['quantity'] - $new_cart_item['data']->get_stock_quantity(), $new_cart_item['variation_id'], woocommerce_get_formatted_variation($variation_data, true), $new_cart_item); } } };
Can anyone help me up with that please?
Regards