%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /var/www/html/friendstravel.al/wp-content/plugins/travel-booking/inc/
Upload File :
Create Path :
Current File : /var/www/html/friendstravel.al/wp-content/plugins/travel-booking/inc/tb_query_phys.php

<?php

/**
 *
 *  Tour Query
 *
 */
class Tour_Query_Phys {
	public function __construct() {
		if ( ! is_admin() ) {
			add_action( 'pre_get_posts', array( $this, 'filter_pre_get_posts' ) );
			add_filter( 'query_vars', array( $this, 'filter_query_vars' ) );
			add_filter( 'woocommerce_get_catalog_ordering_args', array( $this, 'set_order_tour_phys' ) );
		}
	}

	public function filter_pre_get_posts( $q ) {
		if ( ! $q->is_main_query() ) {
			return;
		}

		$tax_product = 'product';
		$tax_tour    = 'tour_phys';

		if ( $GLOBALS['wp_rewrite']->use_verbose_page_rules && isset( $q->queried_object->ID ) && $q->queried_object->ID === (int) get_option( 'tours_show_page_id' ) ) {
			$q = $this->query_for_tour( $q );
		}

		// Fix for verbose page rules
		if ( $GLOBALS['wp_rewrite']->use_verbose_page_rules && isset( $q->queried_object->ID ) && $q->queried_object->ID === wc_get_page_id( 'shop' ) ) {
			$q->set( 'post_type', 'product' );
			$q->set( 'page', '' );
			$q->set( 'pagename', '' );

			// Fix conditional Functions
			$q->is_archive           = true;
			$q->is_post_type_archive = true;
			$q->is_singular          = false;
			$q->is_page              = false;
		}

		if ( $q->get( 'is_tour' ) ) {
			$q = $this->query_for_tour( $q );
		} elseif ( $q->get( 'tour_search' ) ) {
			$q = $this->query_for_tour( $q );
			if ( $q->get( 'name_tour' ) ) {
				$q->set( 's', $q->get( 'name_tour' ) );
			}

			$tax_query_attribute = array(
				array(
					'taxonomy' => 'product_type',
					'field'    => 'slug',
					'terms'    => array( 'tour_phys' ),
					'operator' => 'IN',
				)
			);
			if ( $q->get( 'tourtax' ) ) {
				foreach ( $q->get( 'tourtax' ) as $key => $tax_attribute ) {
					if ( $tax_attribute != '0' ) {
						$q_term                = array(
							'taxonomy' => $key,
							'field'    => 'slug',
							'terms'    => array( $tax_attribute ),
							'operator' => 'IN',
						);
						$tax_query_attribute[] = $q_term;
					}
				}

				$q->set( 'tax_query', $tax_query_attribute );
			}
		}

		if ( 'product' == $q->get( 'post_type' ) && ! $q->get( 'tour_search' ) ) {
			if ( $q->get( 'is_tour' ) ) {
				$q->set( 'tax_query', array(
					array(
						'taxonomy' => 'product_type',
						'field'    => 'slug',
						'terms'    => array( 'tour_phys' ),
						'operator' => 'IN',
					)
				) );
			} else {
				$q->set( 'tax_query', array(
					array(
						'taxonomy' => 'product_type',
						'field'    => 'slug',
						'terms'    => array( 'tour_phys' ),
						'operator' => 'NOT IN',
					)
				) );
			}

			//echo '<pre>' . print_r( $q, true ) . '</pre>';
		}
	}

	private function query_for_tour( $q ) {
		$q->set( 'is_tour', 1 );
		$q->set( 'wc_query', 'tours' );
		$q->set( 'post_type', 'product' );
		$q->set( 'page', '' );
		$q->set( 'pagename', '' );
//		$q->set( 'orderby', 'rand' );
//		$q->set( 'order', 'DESC' );

		if ( get_option( 'tour_expire_on_list' ) && get_option( 'tour_expire_on_list' ) == 'no' ) {
			$q->set( 'meta_query', array(
				array(
					'key'     => '_date_finish_tour',
					'compare' => '>=',
					'value'   => date( 'Y-m-d' ),
					'type'    => 'DATE',
				)
			) );
		}

		// Fix conditional Functions
		$q->is_archive           = true;
		$q->is_post_type_archive = true;
		$q->is_singular          = false;
		$q->is_page              = false;

		return $q;
	}

	public function filter_query_vars( $vars ) {
		$vars[] = 'is_tour';
		$vars[] = 'tour_search';
		$vars[] = 'tourtax';
		$vars[] = 'name_tour';

		return $vars;
	}

	public function set_order_tour_phys( $args ) {
		$args['orderby'] = 'ID';
		if ( isset( $_GET['orderby'] ) ) {
			$args['orderby'] = $_GET['orderby'];
		}

		$args['order'] = 'DESC';

		return $args;
	}
}

$tour_query_physcode = new Tour_Query_Phys();

Zerion Mini Shell 1.0