Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. add_action('transition_post_status', 'new_product_add', 10, 3);
  2. function new_product_add($new_status, $old_status, $post) {
  3. if(
  4. $old_status != 'publish'
  5. && $new_status == 'pending'
  6. && !empty($post->ID)
  7. && in_array( $post->post_type,
  8. array( 'product')
  9. )
  10. ) {
  11. $term = get_term_by('name', 'فروش پیج اینستاگرام', 'product_cat');
  12. wp_set_object_terms($post->ID, $term->term_id, 'product_cat', true);
  13.  
  14. /******************************/
  15. $product = wc_get_product($post->ID);
  16. $product->set_description("something");
  17. $product->save();
  18. /******************************/
  19. }
  20. }
  21.  
  22. wp_update_post( array('ID' => $post->ID, 'post_content' => "something"));
  23.  
  24. Failed to load resource: the server responded with a status of 500 () (index):1
  25.  
  26. add_action('transition_post_status', 'new_product_add', 10, 3);
  27. function new_product_add($new_status, $old_status, $post) {
  28. if(
  29. $old_status != 'publish'
  30. && $new_status == 'pending'
  31. && !empty($post->ID)
  32. && $post->post_type === 'product'
  33. ) {
  34. $term = get_term_by('name', 'فروش پیج اینستاگرام', 'product_cat');
  35. wp_set_object_terms($post->ID, $term->term_id, 'product_cat', true);
  36.  
  37. // unhook this function so it doesn't loop infinitely
  38. remove_action( 'transition_post_status', 'new_product_add', 10 );
  39.  
  40. wp_update_post( array('ID' => $post->ID, 'post_content' => "something"));
  41.  
  42. // re-hook this function
  43. add_action( 'transition_post_status', 'new_product_add', 10, 3 );
  44. }
  45. }
  46.  
  47. add_action('transition_post_status', 'new_product_add', 10, 3);
  48. function new_product_add($new_status, $old_status, $post) {
  49. if(
  50. $old_status != 'publish'
  51. && $new_status == 'pending'
  52. && !empty($post->ID)
  53. && $post->post_type === 'product'
  54. ) {
  55. $term = get_term_by('name', 'فروش پیج اینستاگرام', 'product_cat');
  56. wp_set_object_terms($post->ID, $term->term_id, 'product_cat', true);
  57.  
  58. $product = wc_get_product($post->ID);
  59.  
  60. // unhook this function so it doesn't loop infinitely
  61. remove_action( 'transition_post_status', 'new_product_add', 10 );
  62.  
  63. $product->set_description("something");
  64. $product->save();
  65.  
  66. // re-hook this function
  67. add_action( 'transition_post_status', 'new_product_add', 10, 3 );
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement