<?php
/**
 * Shop Ajax loadMore
 */
// add_action('wp_ajax_nasa_more_product', 'nasa_loadmore_products');
// add_action('wp_ajax_nopriv_nasa_more_product', 'nasa_loadmore_products');
function nasa_loadmore_products() {
    $type = $_REQUEST['type'];
    $post_per_page = $_REQUEST['post_per_page'];
    $page = $_REQUEST['page'];
    $cat = (isset($_REQUEST['cat']) && $_REQUEST['cat'] != '') ? $_REQUEST['cat'] : null;
    $is_deals = $_REQUEST['is_deals'];
    $columns_number = $_REQUEST['columns_number'];
    $columns_number_tablet = $_REQUEST['columns_number_medium'];
    $columns_number_small = $_REQUEST['columns_number_small'];

    $loop = nasa_woocommerce_query($type, $post_per_page, $cat, $page);
    if ($loop->found_posts):
        $layout = isset($_REQUEST['layout']) && $_REQUEST['layout'] == 'list' ? 'list' : 'grid';
        $file = $layout == 'grid' ? 'row_layout.php' : 'list_layout.php';
        
        global $nasa_opt;
        $start_row = $end_row = '';
        include NASA_CORE_PRODUCT_LAYOUTS . 'globals/' . $file;
    endif;
    wp_reset_postdata();
    
    die();
}

// **********************************************************************//
//	Support Multi currency - AJAX
// **********************************************************************//
if (class_exists('WCML_Multi_Currency')) :
    add_filter('wcml_multi_currency_ajax_actions', 'nasa_multi_currency_ajax', 10, 1);
    if (!function_exists('nasa_multi_currency_ajax')) :
        function nasa_multi_currency_ajax($ajax_actions) {
            $ajax_actions[] = 'nasa_more_product';
            
            return $ajax_actions;
        }
    endif;
endif;
