Advertisement
wpgenie

Add note to auction

Jul 6th, 2017
677
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.82 KB | None | 0 0
  1.  add_action( 'woocommerce_after_bid_button', 'custom_add_coment_textarea_on_bid',10);
  2.  
  3.  function custom_add_coment_textarea_on_bid(){
  4.     global $product;
  5.         echo '<div class="coment-on-bid" style="clear:both">';
  6.         _e('Note:');
  7.         echo '<textarea name="coment_on_bid"></textarea>';
  8.         echo '</div>';
  9.  
  10.  }
  11.  
  12. add_filter('woocommerce_simple_auctions_before_place_bid_filter', 'check_if_there_is_note_on_bid',10);
  13.  
  14. function check_if_there_is_note_on_bid($product_data){
  15.  
  16.     global $_POST;
  17.  
  18.     if( (!isset($_POST['coment_on_bid'] ) or !$_POST['coment_on_bid']) && $product_data->get_auction_sealed() == 'yes'){
  19.         wc_add_notice(__('You must add note to your bid!', 'wc_simple_auctions'), 'error');
  20.         return false;  
  21.     }
  22.    
  23.     return $product_data;
  24.  
  25. }
  26.  
  27. add_action('woocommerce_simple_auctions_log_bid', 'custom_save_comment_on_bid', 10, 4 );
  28. function custom_save_comment_on_bid($log_bid_id, $product_id,$bid, $current_user ){
  29.     global $_POST;
  30.        
  31.     if(isset($_POST['coment_on_bid'] ) AND $_POST['coment_on_bid']  AND ($log_bid_id )){
  32.          add_post_meta($data['product_id'], 'bid_note_'.$log_bid_id , sanitize_text_field( $_POST['coment_on_bid']),true);
  33.     }
  34.    
  35. }
  36. add_action('woocommerce_simple_auction_admin_history_header','add_note_woocommerce_simple_auction_admin_history_header');
  37. function add_note_woocommerce_simple_auction_admin_history_header($product){
  38.     if($product->get_auction_sealed() == 'yes'){
  39.         echo '<th>';
  40.         _e('Note', 'wc_simple_auctions');
  41.         echo '</th>';
  42.     }
  43. }
  44. add_action('woocommerce_simple_auction_admin_history_row','add_note_woocommerce_simple_auction_admin_history_row',10,2);
  45. function add_note_woocommerce_simple_auction_admin_history_row($product, $auction_history){
  46.     $bid_note = get_post_meta( $product->get_id(), 'bid_note_'.$auction_history->id, true );
  47.  
  48.         echo '<td>';
  49.         echo $bid_note;
  50.         echo '</td>';
  51.    
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement