Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if(!class_exists('Prinz_wc_product_grid')){
- /**
- * @ Package wordpress
- * @ Sub-Package Prinz
- * @ since 1.0
- */
- class Prinz_wc_product_grid
- {
- function __construct()
- {
- add_action( 'init', array($this, 'prinz_wc_prd_grid') );
- add_shortcode( 'prinz_wc_prd_grid', array($this, 'prinz_wc_pg') );
- }
- public function prinz_wc_pg( $atts ){
- extract( shortcode_atts(
- array(
- 'products_per_page' => 12,
- 'column' => 3,
- ), $atts) );
- $args = array(
- 'post_type' => 'product',
- 'posts_per_page' => $products_per_page,
- 'post_status' => 'publish',
- 'paged' => $paged,
- );
- ob_start();
- $products = new WP_Query( apply_filters( 'woocommerce_shortcode_products_query', $args, $atts ) );
- if ( $products->have_posts() ) : ?>
- <?php do_action( 'woocommerce_before_shop_loop' ); ?>
- <?php woocommerce_product_loop_start(); ?>
- <?php while ( $products->have_posts() ) : $products->the_post(); ?>
- <?php wc_get_template_part( 'content', 'product' ); ?>
- <?php endwhile; // end of the loop. ?>
- <?php woocommerce_product_loop_end(); ?>
- <?php do_action( 'woocommerce_after_shop_loop' ); ?>
- <?php endif;?>
- <?php
- wp_reset_postdata();
- ?>
- <?php
- return '<div class="woocommerce columns-' . $column . '">' . ob_get_clean() . '</div>';
- }
- public function prinz_wc_prd_grid(){
- vc_map(
- array(
- 'name' => __('Woocommerce Product Grid', 'prinz'),
- 'base' => 'prinz_wc_prd_grid',
- 'class'=> '',
- 'category' => 'WooCommerce',
- 'params' => array(
- array(
- 'type' => 'textfield',
- 'holoder' => 'div',
- 'class' => '',
- 'heading' => __( 'Products Per Page', 'prinz' ),
- 'param_name' => 'products_per_page',
- 'value' => __('', 'prinz'),
- ),
- array(
- 'type' => 'textfield',
- 'holoder' => 'div',
- 'class' => '',
- 'heading' => __( 'Products Columns', 'prinz' ),
- 'param_name' => 'column',
- 'value' => __('', 'prinz'),
- ),
- ),
- )
- );
- }
- }
- }
- if(class_exists('Prinz_wc_product_grid')){
- $prinz_wc = new Prinz_wc_product_grid();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement