Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. function edit_user_hours($post){
  2. $post_id = $post->ID;
  3. $customer_id = get_current_user_id();
  4.  
  5. if ( !get_post_meta( $post_id, 'firstpublish', $single = true ) ) {
  6. // ...run code once
  7. $get_table = $wpdb->get_results($wpdb->prepare("SELECT * FROM wp_woocommerce_userHours WHERE userId = %s LIMIT 1", $customer_id));
  8. $get_table = $get_table[0];
  9. $mykey_values = get_post_custom_values( 'hours_taken' );
  10.  
  11. foreach ( $mykey_values as $key => $value ) {
  12. $hourBlock = $value - $get_table->hourBlocks;
  13. }
  14.  
  15. // Do something!
  16. $wpdb->query($wpdb->prepare("UPDATE wp_woocommerce_userHours SET userHours = userHours + $hourBlock WHERE userId = %s LIMIT 1", $customer_id));
  17. die('Data inserted');
  18. update_post_meta( $post_id, 'firstpublish', true );
  19. }
  20. }
  21. add_action( 'draft_to_published', 'a_new_post' )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement