If you’ve already invoked the product, e.g. with
$product = new WC_Product($id);
then you can update the stock level with
$product->set_stock($stock);
For more information check the documentation:
https://docs.woothemes.com/wc-apidocs/class-WC_Product.html#_set_stock
Related Posts:
- How to remove an action within a class with extends
- wc_get_template_part( ‘content’, ‘product’ ) | Where is this file located?
- Create WooCommerce custom stock option that is non-purchasable
- Query multiple post type and categories
- Shipping restrictions with WooCommerce variable products
- WooCommerce – Flat rate shipping based on X quantity steps?
- woocommerce_before_calculate_totals in woocommerce 3.0
- Custom URL for each product variation – rewrite rules
- Where can I find a single item template
- Get WooCommerce product attribute taxonomies in a SQL query on WordPress database
- get deepest Woocommerce Product Category on Archivepage
- how to add custom button on product
- Custom Redirect after registration in WooCommerce
- Wrong product thumbnail size
- Show all author products from specific category
- Sort orders by custom order meta – Woocommerce Orders admin page
- Redirect user to cart page when add to cart button is clicked
- how i can add more required * fields in checkout page?
- Disable Local Attributes woo commerce
- Allow WooCommerce existing customers to checkout without being logged in [closed]
- What will make Woocommerce REST API to issue 401 [closed]
- Woocommerce set cookie after a sale [closed]
- How to upload images from wordpress front-end (the first image must be thumbnail and the rest without first must be in gallery woocommerce product)
- Problems with varibel price [closed]
- the_widget() – filter only one instance
- WooCommerce – Exclude category from snippet
- Replacing products on Woocommerce Product Category with Search Results from SearchWP [closed]
- Creating custom permalink tags for WooCommerce
- Add Custom Slug Tags Per Page
- How to override Woocommerce functionality in Reports section?
- how customise Woocommerce style of custom theme
- Display Sales Quantity by product – Woocommerce [closed]
- wc_get_products() not return the images details
- Adding Product Name on Admin Panel Order list and User’s My-Account Order List
- How to put Stripe first, PayPal second on the checkout page?
- woocommerce – how to get product link by id
- woocommerce_register_post action not firing [closed]
- Woocommerce Email show HTML source code [closed]
- Add SKU in Product Title
- Search in 1) Post, 2) Products (woocommerce) and 3) Custom post type or Taxonomy type on a single page
- Woocommerce REST API – add filter to set maximum query per page for product brands [closed]
- display product’s category static slider name and image in loop wordpress
- Whitespace between product image and gallery on initial load of lightbox product page
- Why is my WordPress login credentials missing, but work with WooCommerce?
- Send admin new order email to logged in user as well
- How to reverse/swap the order of “Sales price” and “Regular prcie” in woocommerce?
- Woocommerce Canceled Order Notification email to admin
- I want hide view more button if price is blank
- Woocommerce before and after shop loop not works
- WooCommerce Admin order – Only run action if user is loaded
- Creating child theme out of Coeur
- Hide sidebar and change layout Blog Page using is_page() function
- Change Out of Stock Error Message in WooCommerce Cart
- Archive product loop does not work with product filters
- I want a simple dropdown for locations in woocommerce
- Getting hundreds of spam orders in WooCommerce with failed stripe payment [closed]
- How to fetch woocommerce highest price and lowest price in custom template page?
- Please help me get rid of conflict with the JavaScript – I’m using WooCommerce with product blocks (Gutenb)
- Order Status without Email check. Only with Order-Number
- WooCommerce pagination: remove ‘page’ from url
- Coupon for product / woocommerce
- How can I show “sold out” instead of “out of stock” for some products with particular tags and categories [closed]
- wc_get_product_id_by_sku() returns 0 for products added programatically via update_post_meta
- Display “Add to basket” and “Read more” buttons in the products shop page with woocommerce
- How Can I fix Woocommerce Billing Address Field? [closed]
- Assign user role by text field in WordPress (Woocommerce) [closed]
- Getting WordPress fatal error when hitting WooCommerce API
- Adding Tracking Details for Advanced Shipment Tracking Plugin From Order Notes
- check shipping amount in woocommerce_after_checkout_validation?
- How to display woocommerce product details on wp page
- How to set up dynamic purchase pixel in Woocommerce?
- MySQL error or data corruption after database migration
- My products are showing “not in stock” and I don’t know why
- Is this code collecting user password?
- Select all products that have a custom field ‘is_new’ set to ‘Yes’
- Woocommerce – Shop can’t find products after domain name change
- “error_message”: “Sorry, you cannot list resources.” using WooCommerce API
- Removing Product from Woocommerce checkout page using Ajax
- add_post_meta on subcription renewal
- login or register then access woocommerce website
- Move woocommerce shop page image to left
- WooCommerce Tax Filter Not Working
- Replace product link with just product name on WooCommerce downloads page
- Woocommerce Product category base same as product base causes 404
- Categories and products in cart Woocommerce
- Update Custom Post Meta Even if Draft
- Clone and modify Woocommerce Products catalog
- Custom CSS Not working on Product page
- How to add ajax loading icon after click add to cart button on woocommerce
- Can’t display product categories on woocommerce getting Invalid taxonomy?
- Send form data to functions.php
- If YITH Wishlist page is set to the WooCommerce my-account endpoint, the endpoints stop working all together. Any solution?
- WooCommerce pay per photo upload [closed]
- Override woocommerce template from parent theme
- Create custom add to cart in WordPress
- WooCommerce – How to add a custom field to only a specific email template [closed]
- Create WordPress account on different domain when WooCommerce order completed
- Creating a woocommerce order when a user creates an account
- I want to update shipping charge $0 for all Woocommeerce Subscription auto-renewal orders
- Conflict between Woocommerce Booking + Woocommerce Product Options [closed]