Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function create_shortcode_product($args, $content) {
- $product_home = new WP_Query(array(
- 'post_type' => 'product',
- 'showposts' => $args['showposts'],
- 'order' => 'DESC',
- 'orderby' => 'random',
- 'tax_query' => array(
- array(
- 'taxonomy' => 'product_cat',
- 'field' => 'term_id',
- 'terms' => $args['id'],
- ),
- ),
- ));
- ob_start(); ?>
- <div>
- <div class="tab_product_main">
- <!-- here is get parent category-->
- </div>
- <div class="tab_product">
- <?php $term_id = $args['id'];?>
- <?php $wcatTerms = get_terms('product_cat', array('hide_empty' => 0, 'orderby' => 'ASC', 'parent' =>$term_id ));
- foreach($wcatTerms as $wcatTerm) :
- $wthumbnail_id = get_woocommerce_term_meta( $wcatTerm->term_id, 'thumbnail_id', true );
- ?>
- <a href="<?php echo get_term_link( $wcatTerm->slug, $wcatTerm->taxonomy ); ?>"><?php echo $wcatTerm->name; ?></a>
- <?php endforeach; ?>
- </div>
- </div>
- <div class="box_ct box_ct_home">
- <div class="ads ads_left_cate fl">
- <div id="img-ads">
- <?php $idcat = $args['id'];
- $thumbnail_id = get_woocommerce_term_meta( $idcat, 'thumbnail_id', true );
- $image = wp_get_attachment_url( $thumbnail_id );
- ?>
- <img src="<?php echo $image; ?>" alt="">
- </div>
- </div>
- <div class="product_row fr flexslider">
- <div class="flex-viewport">
- <ul class="slides">
- <?php if ( $product_home->have_posts() ) :
- while ( $product_home->have_posts() ) :$product_home->the_post(); global $product;?>
- <li class="item_P">
- <div class="n-product">
- <div class="boxgrid">
- <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
- <?php echo get_the_post_thumbnail( get_the_id(), 'full', array( 'class' =>'thumnail') ); ?>
- </a>
- </div>
- <h3 class="product_name"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
- <?php echo number_format($product->get_regular_price(), 0, ',','.');?>
- </div>
- </li>
- <?php endwhile;endif; wp_reset_postdata();?>
- </ul>
- </div>
- </div>
- </div>
- <?php $list_product = ob_get_contents();
- ob_end_clean();
- return $list_product;
- }
- add_shortcode('product', 'create_shortcode_product');
- add_filter('widget_text', 'do_shortcode');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement