26. wrapper content shop page (ok)
Previous25. Thêm chức năng click chuyên mục chuyển lên đường dẫn (ok)Next27. Chức năng lọc sản phẩm trên đường dẫn (ok)
Last updated
Was this helpful?
Last updated
Was this helpful?
C:\xampp\htdocs\test\wp-content\plugins\plugin-name\public\class-wpf-public_ct.php
private function __construct() {
$this->plugin_name = WPF_CT::get_instance()->get_plugin_name();
$this->version = WPF_CT::get_instance()->get_version();
if ( !defined( 'DOING_AJAX' ) || !DOING_AJAX ) {
add_action( 'wp_enqueue_scripts', array( $this, 'register_assets' ) );
add_shortcode('searchandfilter', array($this, 'shortcode'));
add_action( 'wp_head', array( $this, 'result_page' ), 1 );
}
}
public function result_page() {
if ( ! empty( $_POST['wpf_ct'] ) ) {
$option = WPF_Options_CT::get_option( $this->plugin_name, $this->version );
$forms = $option->get();
if ( !empty( $forms[ $_REQUEST['wpf_ct'] ] ) ) {
self::$result_page = WPF_Utils_CT::get_current_page();
$data = $forms[ $_REQUEST['wpf_ct'] ]['data'];
if ( ( !empty( $data['result_type'] ) && $data['result_type'] === 'same_page' ) || self::$result_page == $data['page'] ) {
self::load_wc_scripts();
add_filter( 'body_class', array( $this, 'body_class' ), 10, 1 );
self::$result = $this->get_result( $_REQUEST, $forms[ $_REQUEST['wpf_ct'] ] );
if ( is_singular( 'product' ) ) {
add_filter( 'wc_get_template', array( $this, 'filter_not_found' ), 30, 5 );
} elseif ( is_woocommerce() ) {
global $wp_query;
$this->post_count = $wp_query->post_count;
$wp_query->post_count = 0;
add_action( 'woocommerce_after_main_content', array( $this, 'refresh_post_count' ), 1 );
add_filter( 'wc_get_template', array( $this, 'filter_not_found' ), 30, 5 );
}
}
}
}
if ( is_woocommerce() ) {
add_action( 'woocommerce_before_main_content', array( $this, 'result_container' ), 100 );
add_action( 'woocommerce_after_main_content', array( $this, 'close_div' ), 1 );
}
}
public function result_container( $content = '' ) {
global $wp_current_filter;
if ( !in_array( 'wpseo_head', $wp_current_filter ) ) {//fix conflict with wpseo(calling the content in the header)
remove_filter( 'the_content', array( $this, 'result_container' ), 20, 1 );
}
$slug = !empty( $_REQUEST['wpf_ct'] ) ? sanitize_key( $_REQUEST['wpf_ct'] ) : $this->shortcode_id;
$option = WPF_Options_CT::get_option( $this->plugin_name, $this->version );
$forms = $option->get();
$is_infinity = '';
if ( !empty( $forms[ $slug ] ) ) {
$template = $forms[ $slug ];
$is_result_page = ( !empty( $template['data']['result_type'] ) && $template['data']['result_type'] === 'same_page' ) || self::$result_page == $template['data']['page'];
$show_result_in_same_page = isset( $template['data']['result_type'] ) && $template['data']['result_type'] === 'same_page';
$show_form_in_results = !isset( $template['data']['show_form_in_results'] ) || $template['data']['show_form_in_results'] !== 'show_form_in_results' ? false : true;
$is_infinity = isset( $template['data']['pagination_type'] ) && $template['data']['pagination_type'] !== 'pagination' ? ' wpf_infinity_container' : '';
if ( $is_result_page && !$show_result_in_same_page && $show_form_in_results ) {
$request = array();
$this->shortcode_id = $slug;
if ( ! empty( $_REQUEST['wpf_ct'] ) ) {
$option = WPF_Options_CT::get_option( $this->plugin_name, $this->version );
$forms = $option->get();
if ( !empty( $forms[ $_REQUEST['wpf_ct'] ] ) ) {
$this->shortcode_id = $_REQUEST['wpf_ct'];
$request = $this->parse_query( $_REQUEST, $forms[ $_REQUEST['wpf_ct'] ], false );
}
}
$wpf_form = new WPF_Form_CT( $this->plugin_name, $this->version, $slug );
echo $wpf_form->public_themplate( $forms[ $slug ], self::$result_page, $request );
}
}
if ( is_woocommerce() ) {
echo '<div data-slug="' . $slug . '" class="wpf-search-container' . $is_infinity . '">';
if ( !empty( self::$result ) ) {
ob_start();
}
} else {
return $content . '<div data-slug="' . $slug . '" class="wpf-search-container' . $is_infinity . '">' . self::$result . '</div>';
}
}
Kết quả như ý muốn :))