Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. function create_shortcode_product($args, $content) {
  2. $product_home = new WP_Query(array(
  3. 'post_type' => 'product',
  4. 'showposts' => $args['showposts'],
  5. 'order' => 'DESC',
  6. 'orderby' => 'random',
  7. 'tax_query' => array(
  8. array(
  9. 'taxonomy' => 'product_cat',
  10. 'field' => 'term_id',
  11. 'terms' => $args['id'],
  12. ),
  13. ),
  14. ));
  15.  
  16. ob_start(); ?>
  17. <div>
  18. <div class="tab_product_main">
  19. <!-- here is get parent category-->
  20.  
  21. </div>
  22. <div class="tab_product">
  23. <?php $term_id = $args['id'];?>
  24. <?php $wcatTerms = get_terms('product_cat', array('hide_empty' => 0, 'orderby' => 'ASC', 'parent' =>$term_id ));
  25. foreach($wcatTerms as $wcatTerm) :
  26. $wthumbnail_id = get_woocommerce_term_meta( $wcatTerm->term_id, 'thumbnail_id', true );
  27. ?>
  28. <a href="<?php echo get_term_link( $wcatTerm->slug, $wcatTerm->taxonomy ); ?>"><?php echo $wcatTerm->name; ?></a>
  29. <?php endforeach; ?>
  30. </div>
  31. </div>
  32. <div class="box_ct box_ct_home">
  33. <div class="ads ads_left_cate fl">
  34. <div id="img-ads">
  35. <?php $idcat = $args['id'];
  36. $thumbnail_id = get_woocommerce_term_meta( $idcat, 'thumbnail_id', true );
  37. $image = wp_get_attachment_url( $thumbnail_id );
  38. ?>
  39. <img src="<?php echo $image; ?>" alt="">
  40. </div>
  41. </div>
  42.  
  43. <div class="product_row fr flexslider">
  44. <div class="flex-viewport">
  45. <ul class="slides">
  46. <?php if ( $product_home->have_posts() ) :
  47. while ( $product_home->have_posts() ) :$product_home->the_post(); global $product;?>
  48. <li class="item_P">
  49. <div class="n-product">
  50. <div class="boxgrid">
  51. <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
  52. <?php echo get_the_post_thumbnail( get_the_id(), 'full', array( 'class' =>'thumnail') ); ?>
  53. </a>
  54. </div>
  55. <h3 class="product_name"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
  56. <?php echo number_format($product->get_regular_price(), 0, ',','.');?>
  57. </div>
  58. </li>
  59. <?php endwhile;endif; wp_reset_postdata();?>
  60. </ul>
  61. </div>
  62. </div>
  63. </div>
  64. <?php $list_product = ob_get_contents();
  65.  
  66. ob_end_clean();
  67.  
  68. return $list_product;
  69. }
  70.  
  71. add_shortcode('product', 'create_shortcode_product');
  72.  
  73. add_filter('widget_text', 'do_shortcode');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement