<?php


// [xs_pricing table_group="" col=""]   
function xs_pricing($atts) {
    extract(shortcode_atts(array(
        "table_group" => '',
        "col" => '3'
                    ), $atts));

    global $within_section;
    $html = '';
    if ($col == '4') {
        $col_class = 'col-md-3 col-sm-6';
    } else {
        $col_class = 'col-md-4 col-sm-4';
    }
    // WP_Query arguments
    $args = array(
        'post_type' => 'xs_pricing_table',
        'xs_pricing_tables' => $table_group,
        //'orderby' => 'menu_order',
        'order' => 'DSC'
    );
    global $post;
    // The Query
    $query = new WP_Query($args);
    // The Loop
    if ($query->have_posts()) {
        while ($query->have_posts()) {
            $query->the_post();

            $arr = get_post_meta($post->ID, 'xs_pricing_feature', true);
            $features = '';

            foreach ($arr as $v) {
                $features .= '<li>' . $v['title'] . '</li>';
            }
            if (get_post_meta($post->ID, 'xs_pricing_price', true) != '') {
                $price = '<small>' . get_post_meta($post->ID, 'xs_pricing_cur', true) . '</small>' . get_post_meta($post->ID, 'xs_pricing_price', true) . ' <span class="hidden price-data-json" data-xsjson=\'{ "price": "' . get_post_meta($post->ID, 'xs_pricing_price', true) . '", "name": "' . $post->post_title . '", "cur": "' . get_post_meta($post->ID, 'xs_pricing_cur', true) . '" }\'></span>';
            } else {
                $price = 'Free <span class="hidden price-data-json" data-xsjson=\'{ "price": "free", "name": "' . $post->post_title . '", "cur": "' . get_post_meta($post->ID, 'xs_pricing_cur', true) . '" }\'></span>';
            }

            $html .= '<div class="' . $col_class . ' col-xs-12 text-center">
						<div class="priceBox">
							<div class="heading">
								<h2>' . $post->post_title . '</h2>
							</div>
							<div class="price text-center"> <strong>' . $price . '</strong> </div>
							<ul class="text-center">' . $features . '</ul>
							<a class="btn" href="' . esc_url(get_post_meta($post->ID, 'xs_pricing_button_link', true)) . '" title="' . get_post_meta($post->ID, 'xs_pricing_button_text', true) . '">' . get_post_meta($post->ID, 'xs_pricing_button_text', true) . '</a> 
						</div>
					</div>
';
        }
    }
    // Restore original Post Data
    wp_reset_postdata();
    $klass = ($within_section == 'y') ? ('section xs-section bottom-margin clearfix') : ('clearfix');
    return '<div class="' . $klass . '">' . $html . '</div>';
}

add_shortcode('xs_pricing', 'xs_pricing');
