• Resolved bislamovic

    (@bislamovic)


    Hi,

    I have installed WooCommerce Bookings plugin 1.11.2 and I want to have “# of Persons” in my report (I am using Person types but for now it is not important to have them separated).

    In regular Booking reports (Booking>All Bookings) there is “# od Persons” number, but I can not find it in any Product field, Order item field, Taxonomy or Meta key.

    • This topic was modified 6 years, 3 months ago by bislamovic.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author algol.plus

    (@algolplus)

    hi

    Please, adapt code https://algolplus.com/plugins/snippets-plugins/#bookings.

    You must call get_person_counts(), but it returns array. So correct line will be
    $person_count = array_sum( $this->booking->get_person_counts() );

    thanks, Alex

    • This reply was modified 6 years, 3 months ago by algol.plus.
    • This reply was modified 6 years, 3 months ago by algol.plus.
    Plugin Author algol.plus

    (@algolplus)

    Thread Starter bislamovic

    (@bislamovic)

    Thank you for fast reply. Unfortunately I can not get it.

    class WOE_Bookings{
    	function __construct() {
    		add_filter('woe_get_order_product_fields',array($this,'add_product_fields') );
    		add_filter('woe_get_order_product_item',array($this,'fetch_booking') );
    	  
    	    add_filter('woe_get_persons_count', array($this, 'get_pax_count'), 10, 4 );
    	}	
    	
    	function add_product_fields($fields) {
    	  
    	    $fields['# of Persons'] = array('label'=>'# of Persons','colname'=>'# of Persons','checked'=>1,'segment'=>'cart'); 
    		return $fields;
    	}
    	
    	// booking for item 
    	function fetch_booking($item) {
    		global $wpdb;
    		$this->booking = false;
    		$booking_id = $wpdb->get_var( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key= '_booking_order_item_id' AND meta_value=" . intval( $item->get_id() ) );
    		if( $booking_id ) {
    			$this->booking =  new WC_Booking($booking_id);
    		}
    		return $item;
    	}
      //count pax
      function get_pax_count($person_count) {
        	$person_count = array_sum( $this->booking->get_person_counts() );
    		return $person_count;
      }
    	
    }	
    new WOE_Bookings();
    Plugin Author algol.plus

    (@algolplus)

    hi

    here is not tested code.
    I only fixed hooks and field names.

    class WOE_Bookings{
    	function __construct() {
    		add_filter('woe_get_order_product_fields',array($this,'add_product_fields') );
    		add_filter('woe_get_order_product_item',array($this,'fetch_booking') );
    	  
    	    add_filter('woe_get_order_product_value_num_of_persons', array($this, 'get_pax_count'), 10, 4 );
    	}	
    	
    	function add_product_fields($fields) {
    	    $fields['num_of_persons'] = array('label'=>'# of Persons','colname'=>'# of Persons','checked'=>1,'segment'=>'cart'); 
    		return $fields;
    	}
    	
    	// booking for item 
    	function fetch_booking($item) {
    		global $wpdb;
    		$this->booking = false;
    		$booking_id = $wpdb->get_var( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key= '_booking_order_item_id' AND meta_value=" . intval( $item->get_id() ) );
    		if( $booking_id ) {
    			$this->booking =  new WC_Booking($booking_id);
    		}
    		return $item;
    	}
      //count pax
      function get_pax_count($value,$order, $item, $product) {
        	$person_count = $this->booking ? array_sum( $this->booking->get_person_counts() ) : $value;
    		return $person_count;
      }
    	
    }	
    new WOE_Bookings();
    Thread Starter bislamovic

    (@bislamovic)

    That’s it. It is working!
    Thank you very much.

    • This reply was modified 6 years, 3 months ago by bislamovic.
    Plugin Author algol.plus

    (@algolplus)

    you’re welcome.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘# of persons in bookings’ is closed to new replies.