To set default values of a new post, you can try this code :
$postType = "product";
add_action("save_post_" . $postType, function ($post_ID, \WP_Post $post, $update) {
if (!$update) {
// default values for new products
update_post_meta($post->ID, "_manage_stock", "yes");
update_post_meta($post->ID, "_stock", 1);
return;
}
// here, operations for updated products
}, 10, 3);
Related Posts:
- Woocommerce get selected shipping zone id for the current user
- Query WooCommerce orders grouped by several order statuses
- retrieve thumbnail from post ID of best selling product in category
- Display a selected custom product option in WooCommerce cart
- How to change “Shipping Calculator “field label on Cart Page – woocommerce? [closed]
- Cleanest/Fastest way to avoid calling and retrieving data from the database multiple times?
- Replace existing content from specific WooCommerce admin orders list column
- Woocommerce – How to get products which have a sale between 20% to 40%? [closed]
- Woocommerce: Is it possible to overide the settings for allowing to purchase out of stock products [closed]
- How does WooCommerce ensure that a product doesn’t run out of stock during payment? [closed]
- Woocommerce filter cart and category specific quantity [closed]
- How to get woocommerce cart content without an action?
- WooCommerce: Add Payment Gateway Field to Webhooks [closed]
- Woocommerce product download URL
- woocommerce – hide payment method in new order email
- Change the URL of an image from wp_get_attachment_image_src except in the frontpage
- How can I use wp_query to show all product data using just the products ID?
- Get stock by custom meta field on all Woocommerce variable products
- Set a condition based on WooCommerce checkout city field while placing order
- woocommerce subscriptions – get expiration date [closed]
- Call global variable array() in woocommerce child/template
- Remove price from Woocommerce variable product dropdown menu
- Woocommerce hook run after an Order been created through REST API
- Get and insert order email address to the PHP template inside HTML text
- Woocommerce api: create product with images – bad request
- do search in two site and show the result in first site
- Woocommerce: hook action/filter I could use to add variation id and price with each attribute opt on WooCommerce Rest api
- How can I pass a custom/dynamic product to the Woocommerce cart?
- WooCommerce custom product dimensions
- WordPress Woocommerce – Product Type [closed]
- Pagination for custom shop loop woocommerce
- How to get private property in parent class into extended class?
- Woocommerce Email attachments not working – file not being attached
- get_total () returns 0 – woocommerce [closed]
- email alert for product availability
- How to rename woocommerce-billing-fields
- WooCommerce pages looks unstyled
- Disable if there are no children – Woocommerce
- Create a package of products as one Item in woocommerce?
- fetch woocommerce product with custom taxonomy
- After disabling WPML multi currency, the currency is still handled by the WPML
- Custom Taxonomy Select Menu: Setting default option value?
- How can i programmatically change the SKU of a product based on product variation?
- Execute PHP code only with specific user role
- Woocommerce Custom Meta Boxes- How to only display if they actually have content
- Add a custom WooCommerce settings tab with sections
- Display Sibling WooCommerce Product Categories on Archive Page
- Checking page before applying image restrictions while uploading
- How to sort WooCommerce products page by latest in-stock items first?
- WP_Query for woocommerce products with a pattern as a post_title
- WordPress Fresh Install Errors (Woocommerce specifically now)
- Generate images with html2canvas and the woocommerce api
- How to update ticket price programatically when adding to cart and checkout in woocommerce
- Woocommerce – Exclude variation attribute on specific variation
- Get WooCommerce products with similar SKU
- PHP function for horizontal Woocommerce thumbnails and badges
- Use CSS tag inside PHP code
- Set ACF on order during checkout
- Hide payment method based on user role AND minimum cart value
- WooCommerce display price before add to cart [closed]
- Get the same SKU from woocommerce itself for simple and variable products
- How can I show how much water got saved on this order (making use of the number of items bought) on a thank-you-page?
- Woocommerce checkout page – custom field checkbox value into email
- WooCommerce function not working correctly after moving from the functions.php into a class
- Filter for product subcategory listing page load
- Reduce Stock Based on Custom Variation Field Rather than Attribute (Working Script)
- Set notification if is two product category in cart
- WooCommerce – template_redirect if is_checkout AND order has been paid?
- AJAX to add to cart multiple products woocommerce
- Make WooCommerce product categories only show images on homepage
- ACF under category name in shop page [closed]
- WooCommerce Quantity in Dropdown menu instead of clasic [closed]
- WP_Query To Display Product Of Brand On Taxonomy Page
- Reverse Cross-Sells (WooCommerce)
- Hot to edit WooCOmmerce dashboard?
- WooCommerce subcategories help
- WooCommerce multiple custom fields code
- Search function not working
- loop to return tags in woocommerce in alphabetical order?
- How to have more than one ID included in the exclude command?
- I was wondering if it’s possible to implement card.js on WordPress
- wp_query beginner
- Woocommerce custom field on emails outputs ‘Array’
- WordPress using get_term to retreive slug not working as expected
- Can’t make product images clickable
- WooCommerce – Print Processing orders [closed]
- Hide cart when empty [closed]
- WooCommerce Custom Pagination
- Order woo products, but first products must be with acf fields
- Warning: Attempt to read property “term_id” on int – Woocommerce
- Show button in header when product custom field is not empty
- WordPress 6.1.1 UTF8 Slug Limit Increase
- How call WordPress shortcode inside function file
- Woocommerce Convert existing order to the cart
- strict custom php script on specific product category [closed]
- How to change shipping method title based on cart amount?
- Woocommerce product variations getting created without attribute values selected
- How to add SKU and remove product title from WooCommerce url?
- Product Search in search.php
- using custom pages for myaccount in woocommerce