Try like
function add_this_to_new_products( $new_status, $old_status, $post ) {
global $post;
if ( $post->post_type !== 'product' ) return;
if ( 'publish' !== $new_status or 'publish' === $old_status ) return;
add_post_meta( $post->ID, 'total_amount', '0', true ); // This is the action to take
}
add_action( 'transition_post_status', 'add_this_to_new_products', 10, 3 );
Related Posts:
- Adding an action within a function that is being called by add_filter
- Remove action on product archive page [closed]
- How to remove_action inside class [duplicate]
- Unable to programmatically remove product from WooCommerce cart
- Is there a Woocommerce hook that fires when applying a coupon but before checking if it’s valid?
- What is the action hook for an order that fails on frontend checkout in WooCommerce?
- Remove action added through function
- Which hook should I use to capture $_POST(‘password’) via profile update and password reset
- How can I add an additional action button into the woocommerce admin order page?
- Edit WooCommerce product content based on category
- How to list all WC products by their attributes values?
- WooCommerce Hook: Content get’s displayed twice and not AFTER the order total
- password_reset doesnt work
- Woocommerce – Adding row to cart table
- Functions.php change for Woocommerce not working
- Display custom product option in admin order details
- Assign user role by text field in WordPress (Woocommerce) [closed]
- Combine one action and one filter
- How can I send information when a order is completed to my own POS?
- Parameters in woocommerce_before_add_to_cart_button hook
- How to change lost password email text using custom plugin wordpress?
- Overriding Plugin function in your child theme
- How can I locate where the actions are defined? [duplicate]
- add_action don’t updates theme layout when using values from the WordPress customizer
- Woocommerce add a text field if specific option is selected
- add_filter not works in ajax
- How Do I Access Parameters Emitted by an Action?
- Reposition variation stock message
- WooCommerce Webhook Action When a New Product Review was Submitted/Created
- WooCommerce: Can’t use wc_get_products for custom REST API endpoints
- How to disable Woocommerce password recovery and use the default WordPress password reset page?
- Display WooCommerce size product attribute on shop page
- WooCommerce add_to_cart() with custom price [closed]
- Declaring custom woocommerce product type as virtual / downloadable only [closed]
- Redirect if current user is logged out and current page is /my-account
- Display a list subcategories under the main product category thumbnails?
- WooCommerce Apply Coupon to order AFTER taxes
- Rewriting Woocommerce Product Filters To URL Segments
- How to Change WooCommerce Variable product pricing by SKU or visible children id
- Is it possible to cache ?wc-ajax=get_variation
- echo product id and product_item_key in cart [closed]
- Redirect the single product page link to the shop page
- Is WooCommerce updates for WordPress necessary? [closed]
- How can I display *only* the child category of a product?
- why featured product not updated in postmeta table in woocommerce?
- Display list of categories that contain products with a specific tag
- How to display empty stars on products with woocommerce?
- WooCommerce limited role
- Skip WooCommerce 4.5.x onboarding with WP-CLI [closed]
- CampaignMonitor for WooCommerce – Move subscribe button [closed]
- Automatically making a newly saved payment method default in WooCommerce
- WooCommerce update_shipping_method ajax call wipes shipping method set on non-checkout page [closed]
- Product options/variations notice displays as an Alert [closed]
- create comment box in woo-commerce shop order [closed]
- Product variation attributes does not appear as it should in the cart – woocommerce [closed]
- Hide decimal on hompage, category and product page
- Woocommerce: how to know if the customer is canceled the order or the shop owner? [closed]
- Adding Buy Button to Blog Post (Woocommerce) [closed]
- How to replace WooCommerce Product Gallery Trigger icon using PHP/CSS? [closed]
- woocommerce_order_status_completed not working
- Synchronise Renewals on existing subscriptions [closed]
- How to show the urls inside the simple product when the customer buys it?
- Custom template – query issues
- Sort downloads by most recently purchased first in my account WooCommerce [closed]
- Hide shipping method in woocommerce if custom checkbox field is selected
- how to change add to cart button to call for price button in one of product variation?
- apply_filter and add_filter conflict
- Migrating WordPress + WooCommerce from server to Local
- wp-cron and woocommerce subscriptions killing performance
- Getting in an exception for get product detail by id in woocommerce REST api
- How to make wocommerce shop products same heigt
- Woocommerce Variation product added twice to cart
- Woocommerce product query not working in other WPML languages
- Woocommerce Ajax add to cart redirect to homepage
- How to merge 2 accounts with same email address after merge of 2 woocommerce databases
- Get $order in wp_head
- How to save a Woocomerce metabox input as a metadata field
- Adding order details in woocommerce all booking dashboard
- populating extra field with woocommerce categories
- Woocommerce Shop Manager Capabilities
- How to tell woocommerce slider to use thumbnails
- Add customer name to woocommerce email-header.php heading
- woocommerce sort by dropdown styling
- Mysql query – amount spent by customer
- Integration widget Mondial Relay Js
- Custom Registration Fields woocommerce
- bulk media crop for featured images
- WooCommerce set specific currency on site shop
- WooCommerce shop, my account, cart every page redirect to home page [closed]
- How to edit woocommerce checkout fields
- Include customer details in woocommerce 3rd part plugin email
- how to add a page to a plugin?
- Unable to get product category
- Woocommerce: how to make only certain products shippable?
- Customer email notification upon order update in woocommerce
- How can i hide a specific class when cart subtotal is above a certain amount
- Update WooCommerce Short Description using SQL
- How to display woo commerce shipping_method on the product page
- Product data field for Woo Commerce is blank?
- WP All Import – Set product product status with xpath