Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Change description on specific WooCommerce product status change

To avoid an infinite loop on transition_post_status hook when using wp_update_post(), try:

add_action('transition_post_status', 'new_product_add', 10, 3);
function new_product_add($new_status, $old_status, $post) {
    if( 
        $old_status != 'publish' 
        && $new_status == 'pending' 
        && !empty($post->ID) 
        && $post->post_type === 'product'
    ) {
        $term = get_term_by('name', 'فروش پیج اینستاگرام', 'product_cat');
        wp_set_object_terms($post->ID, $term->term_id, 'product_cat', true);

        // unhook this function so it doesn't loop infinitely
        remove_action( 'transition_post_status', 'new_product_add', 10 );

        wp_update_post( array('ID' => $post->ID, 'post_content' => "something"));

        // re-hook this function
        add_action( 'transition_post_status', 'new_product_add', 10, 3 );
    }
}

Or:

add_action('transition_post_status', 'new_product_add', 10, 3);
function new_product_add($new_status, $old_status, $post) {
    if( 
        $old_status != 'publish' 
        && $new_status == 'pending' 
        && !empty($post->ID) 
        && $post->post_type === 'product'
    ) {
        $term = get_term_by('name', 'فروش پیج اینستاگرام', 'product_cat');
        wp_set_object_terms($post->ID, $term->term_id, 'product_cat', true);

        $product = wc_get_product($post->ID);

        // unhook this function so it doesn't loop infinitely
        remove_action( 'transition_post_status', 'new_product_add', 10 );

        $product->set_description("something");
        $product->save();

        // re-hook this function
        add_action( 'transition_post_status', 'new_product_add', 10, 3 );
    }
}

It may solve your issue.

This is documented here on wp_update_post() for save_post hook.

Related Posts:

  1. Append a term to WooCommerce product existing product category terms
  2. How to change / delete product short description in Woocommerce
  3. How to VAR_DUMP a $variable during checkout process (Is my product meta callable?)
  4. Exclude product attributes from taxonomy terms loop
  5. Add Custom Category Description When Empty
  6. Using zip code to display custom data in Admin Order Details
  7. Reverse Cross-Sells (WooCommerce)
  8. New term taxonomy and description in front page. Input’s
  9. WordPress using get_term to retreive slug not working as expected
  10. Why my filterable portfolio page work not perfectly between slug button and slug output WORDRPESS?
  11. dividing sub-categories by parent category – WordPress
  12. Show prices with tax in Woocommerce Mini Cart [closed]
  13. Woocommerce product variation backorder
  14. Status 400 for AJAX POST Request with admin-ajax.php
  15. Sort custom meta column by other meta value
  16. Problem with custom plugin using AJAX to pull info from php file
  17. Woocommerce hook run after an Order been created through REST API
  18. How can I apply_filters from inside a function?
  19. Get and insert order email address to the PHP template inside HTML text
  20. Modify HTML structure of fields in woocommerce checkout form
  21. Store multiple custom field as post meta per post(css, js, html, 2 link) [closed]
  22. Pass Category Name, Description and Photo into variables to pass to jQuery
  23. Auto-update products after they were published – Woocommerce
  24. Reload part of checkout on changed shipping method
  25. How to get all shipping rates and costs without session in woocommerce?
  26. Move category description below post list in blog
  27. Display a specific category of products in shop page and disable code for specific actions
  28. If no products are on sale – hide ID or class
  29. Woocommerce related product text
  30. Woocommerce api: create product with images – bad request
  31. Trying to build simple deposit code that hooks into woocommerce
  32. Creating user status mode in WordPress
  33. WooCommerce Webhooks not firing because of error in wp-includes/meta.php
  34. Different Minimum Order Amounts based on Shipping Zone [closed]
  35. Need help with Google drive API [closed]
  36. do search in two site and show the result in first site
  37. Woocommerce: hook action/filter I could use to add variation id and price with each attribute opt on WooCommerce Rest api
  38. Add a product to checkout via form
  39. Trying to place a custom field after the total section in the checkout page in woocommerce
  40. How to get original custom taxonomy slug after the slug has been rewritten?
  41. WordPress default Search function inconsistent in WooCommerce Product Titles
  42. Which field should I edit to make the checkbox marked by default?
  43. Displaying Woocommerce Product Category in WordPress
  44. Is it possible to intercept all ajax requests and get the parameters and the returns?
  45. WooCommerce: How can I get orders with a custom ID in order meta data object?
  46. wordpress + woocommerce display product with additional information [closed]
  47. how to fix error “called incorrectly, should not be accessed directly”?
  48. Function works when I don’t login to WordPress but when I login then it doesn’t work
  49. How to auto fetch customer details in Woocommerce in checkout page
  50. Displaying custom taxonomy on WooCommerce product page
  51. Sum the total amount of a specific product purchased per user and display in table
  52. Change “add to cart” button color based on Woocommerce product category [closed]
  53. How can I get the values of my WordPress $wpdb query in Jquery?
  54. How can I pass a custom/dynamic product to the Woocommerce cart?
  55. Add to cart function not working for first product when cart is empty [closed]
  56. I want to add custom add to cart link [closed]
  57. How to make products with no cost in WooCommerce
  58. Woocommerce : Can’t get product info in loop
  59. WooCommerce custom product dimensions
  60. Trouble checking if custom woocommerce checkout field is empty or not
  61. Incorrect amount of posts returned when filtering related Woo products by custom taxonomy
  62. Validation algorithm in checkout field
  63. Get term siblings of current child taxonomy
  64. How can I add an area/option for a custom page description?
  65. Archive post by meta value + 24hours
  66. How to get post’s current parent term ID?
  67. How do I remove the product thumbnail link from a specific div in Woocommerce? [closed]
  68. My new button is in the wrong place
  69. Insert term and child term from frontend
  70. WordPress Woocommerce – Product Type [closed]
  71. WordPress update_post_meta updating with empty meta_value field [closed]
  72. Pagination for custom shop loop woocommerce
  73. How to add specific meta tags to head of cart and checkout pages in woocommerce?
  74. How to remove woocommerce_breadcrumb() from do_action( ‘woocommerce_before_main_content’ ); [closed]
  75. Is it possible to retrieve all posts with a certain value for metadata?
  76. Get post id within comments loop
  77. Woocommerce change prices for a certain country [closed]
  78. How to get private property in parent class into extended class?
  79. Non-Closing PHP Query in WordPress Loop
  80. echo something inside a shortcode
  81. Replace Woocommerce “add to cart” to be “Download” button [closed]
  82. Is there a way to hook or call a custom woocomerce template that is not part of the default templates of woocommerce?
  83. List taxonomy term slugs within shortcode (do_shortcode)
  84. get taxonomy thumbnail and use it as a variable in code
  85. Woocommerce Email attachments not working – file not being attached
  86. Include Parent Term in wp_list_categories
  87. Function returns text instead of html [closed]
  88. Extend Woocommerce Widget Class – WC_Widget_Product_Categories
  89. Single Quotes in .php file doesn’t load website
  90. Add post with approval by the admin
  91. How can I access string value in an array?
  92. Copy taxonomy terms from one post to another programmatically
  93. get_total () returns 0 – woocommerce [closed]
  94. Querying Database with wpdb
  95. Limit Taxonomy Output in Conditional Statement
  96. How to remove coupon dropdown feature
  97. Get all categories post is not in
  98. How can I display a div ONLY if it is not a certain term page
  99. Woocommerce display one random product via php
  100. Hide image if taxonomy term is empty
Categories PHP Tags description, php, post-meta, terms, woocommerce-offtopic
I want to get the home root path
Updating Custom WordPress User Meta Field via REST API

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress