Advertisement
Guest User

wc-vc

a guest
Aug 19th, 2017
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. <?php
  2. if(!class_exists('Prinz_wc_product_grid')){
  3. /**
  4. * @ Package wordpress
  5. * @ Sub-Package Prinz
  6. * @ since 1.0
  7. */
  8. class Prinz_wc_product_grid
  9. {
  10.  
  11. function __construct()
  12. {
  13. add_action( 'init', array($this, 'prinz_wc_prd_grid') );
  14. add_shortcode( 'prinz_wc_prd_grid', array($this, 'prinz_wc_pg') );
  15. }
  16.  
  17. public function prinz_wc_pg( $atts ){
  18.  
  19. extract( shortcode_atts(
  20. array(
  21. 'products_per_page' => 12,
  22. 'column' => 3,
  23. ), $atts) );
  24.  
  25. $args = array(
  26. 'post_type' => 'product',
  27. 'posts_per_page' => $products_per_page,
  28. 'post_status' => 'publish',
  29. 'paged' => $paged,
  30. );
  31.  
  32. ob_start();
  33.  
  34. $products = new WP_Query( apply_filters( 'woocommerce_shortcode_products_query', $args, $atts ) );
  35.  
  36. if ( $products->have_posts() ) : ?>
  37.  
  38. <?php do_action( 'woocommerce_before_shop_loop' ); ?>
  39. <?php woocommerce_product_loop_start(); ?>
  40.  
  41. <?php while ( $products->have_posts() ) : $products->the_post(); ?>
  42.  
  43. <?php wc_get_template_part( 'content', 'product' ); ?>
  44.  
  45. <?php endwhile; // end of the loop. ?>
  46.  
  47. <?php woocommerce_product_loop_end(); ?>
  48. <?php do_action( 'woocommerce_after_shop_loop' ); ?>
  49.  
  50. <?php endif;?>
  51.  
  52. <?php
  53. wp_reset_postdata();
  54. ?>
  55. <?php
  56. return '<div class="woocommerce columns-' . $column . '">' . ob_get_clean() . '</div>';
  57. }
  58.  
  59. public function prinz_wc_prd_grid(){
  60. vc_map(
  61. array(
  62. 'name' => __('Woocommerce Product Grid', 'prinz'),
  63. 'base' => 'prinz_wc_prd_grid',
  64. 'class'=> '',
  65. 'category' => 'WooCommerce',
  66. 'params' => array(
  67. array(
  68. 'type' => 'textfield',
  69. 'holoder' => 'div',
  70. 'class' => '',
  71. 'heading' => __( 'Products Per Page', 'prinz' ),
  72. 'param_name' => 'products_per_page',
  73. 'value' => __('', 'prinz'),
  74. ),
  75. array(
  76. 'type' => 'textfield',
  77. 'holoder' => 'div',
  78. 'class' => '',
  79. 'heading' => __( 'Products Columns', 'prinz' ),
  80. 'param_name' => 'column',
  81. 'value' => __('', 'prinz'),
  82. ),
  83. ),
  84. )
  85. );
  86. }
  87. }
  88. }
  89.  
  90. if(class_exists('Prinz_wc_product_grid')){
  91. $prinz_wc = new Prinz_wc_product_grid();
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement