Last active
February 3, 2018 22:29
-
-
Save jinsley8/6dddf82ddcdd37900077ec34694c5470 to your computer and use it in GitHub Desktop.
product loop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Callback function of the shortcode. | |
*/ | |
function ot_brand_products_cb($atts, $content){ | |
/** | |
* Setting variable value none. | |
*/ | |
$content = null; | |
/** | |
* Checking if user logged in. | |
*/ | |
if(is_user_logged_in() && 'administrator' != get_user_role() ): | |
/** | |
* User id of the logged in user. | |
*/ | |
$user_id = get_current_user_id(); | |
/** | |
* Getting user meta by id. | |
*/ | |
$data = get_user_meta($user_id); | |
/** | |
* Getting entry id of gfrom. | |
*/ | |
$entry_id = $data['_gform-entry-id']['0']; | |
/** | |
* Getting global $wpdb to run custom query. | |
*/ | |
global $wpdb; | |
/** | |
* Getting results from custom query. | |
*/ | |
$results = $wpdb->get_results( "SELECT * FROM wp_rg_lead_detail WHERE lead_id = $entry_id AND field_number = 13", OBJECT ); | |
/** | |
* Getting assigned categories id's | |
*/ | |
$assigned_cats = json_decode($results['0']->value); | |
$assigned_cats = (array) $assigned_cats; | |
if(empty($assigned_cats)){ | |
$content = null; return; | |
} | |
$inner_array = array(); | |
$tab_heading_li = null; | |
$parent_id = 1492; | |
$terms = array( | |
'taxonomy' => 'product_cat', | |
'parent' => $parent_id | |
); | |
$terms = get_terms($terms); | |
$terms_id_arr = array(); | |
foreach ($terms as $key => $value) { | |
if(in_array($value->term_id, $assigned_cats)): | |
$terms_id_arr[] = $value->term_id; | |
$tab_heading_li .= '<li><button class="button product_cat_'.$value->slug.'" data-filter=".product_cat-'.$value->slug.'">'.$value->name.'</button></li>'; | |
endif; | |
} | |
$args = array( | |
'post_type' => 'product', | |
'posts_per_page' => 1000, | |
'tax_query' => array( | |
array( | |
'taxonomy' => 'product_cat', | |
'field' => 'term_id', | |
'terms' => $terms_id_arr | |
), | |
), | |
); | |
$query = new WP_Query( $args ); | |
$prod_html = null; | |
$i = null; | |
// The Loop | |
if ( $query->have_posts() ) { | |
echo '<ul>'; | |
while ( $query->have_posts() ) { | |
$i++; | |
$query->the_post(); | |
$product = new WC_Product( get_the_ID() ); | |
$prod_clases = null; | |
$post_classess = get_post_class(array('product-grid-item', 'woodmart-hover-quick')); | |
foreach ($post_classess as $post_class) { | |
$prod_clases .= ' '. $post_class; | |
} | |
$prod_html .= ' | |
<div class="col-xs-6 col-sm-4 col-md-3 col-md-2 '.$prod_clases.' element-item portfolio-thumbnail" style="position: absolute; left: 0px; top: 0px;"> | |
<div class="element-inner"> | |
<a class="quick-view-icon open-quick-view" data-loop="'.$i.'" data-loop-name="main-loop" data-id="'.get_the_ID().'" href="'.admin_url('admin-ajax.php').'?prod_id='.get_the_ID().'&action=woodmart_quick_view"><i class="fa fa-search fa-lg" aria-hidden="true"></i> | |
<span class="tooltiptext">Quick View</span> | |
</a> | |
<a class="element-image" href="'.get_the_permalink().'"> | |
'.get_the_post_thumbnail(get_the_ID(), 'shop_catalog ').' | |
<div class="woodmart-add-btn">'. do_action( 'woocommerce_after_shop_loop_item' ).'</div> | |
</a> | |
<div class="element-content"> | |
<a href="'.get_the_permalink().'" class="element-content-title">'.get_the_title().'</a> | |
<span class="price">'.$product->get_price_html().'</span> | |
</div> | |
</div> | |
</div>'; | |
} | |
/* Restore original Post Data */ | |
wp_reset_postdata(); | |
} | |
$content = ' | |
<section class="custom-isotopes"> | |
<div class="row"> | |
<div class="col-sm-12 no-padding"> | |
<div class="filter-content"> | |
<h2>SHOP HOT BRANDS</h2> | |
<ul id="hot_brands_filters" class="filter-list"> | |
'. $tab_heading_li .' | |
</ul> | |
</div> | |
</div> | |
</div> | |
<div class="row hot-brands-grid"> | |
'.$prod_html.' | |
</div> | |
</section> | |
'; | |
else: $content = null; | |
endif; | |
echo $content; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment