| Server IP : 213.186.33.4 / Your IP : 216.73.216.146 Web Server : Apache System : Linux webm005.cluster103.gra.hosting.ovh.net 6.18.39-ovh-vps-grsec-zfs+ #1 SMP PREEMPT_DYNAMIC Tue Jul 21 12:03:15 CEST 2026 x86_64 User : karinebmkh ( 644538) PHP Version : 8.4.22 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/karinebmkh/www2/wp-content/plugins/glaza-core/widgets/ |
Upload File : |
<?php
if ( ! class_exists( 'glaza_widget_wc_best_selling' ) ) :
class glaza_widget_wc_best_selling extends WP_Widget {
function __construct() {
$widget_ops = array(
'classname' => 'widget-wc-best-selling',
'description' => esc_html__( 'Display all best selling products', 'glaza-core' )
);
parent::__construct( 'wc_best_selling', esc_html__( '[Full Width/Content] Best Selling Products', 'glaza-core' ), $widget_ops );
}
function widget( $args, $instance ) {
$instance = wp_parse_args( $instance, array(
'title' => esc_html__( 'Best Selling Products', 'glaza-core' ),
'title_url' => '',
'posts_per_page' => 8,
'columns' => 4,
'style' => 'carousel'
) );
$instance['title'] = apply_filters( 'widget_title', $instance['title'] );
echo $args['before_widget'];
if ( ! empty( $instance['title'] ) ) : ?>
<header class="block-header">
<h3 class="block-title">
<?php if ( ! empty( $instance['title_url'] ) ) : ?>
<a href="<?php echo esc_url( $instance['title_url'] ); ?>" rel="bookmark"><?php echo esc_html( $instance['title'] ); ?></a>
<?php else : ?>
<?php echo esc_html( $instance['title'] ); ?>
<?php endif; ?>
</h3>
</header>
<?php endif;
if ( ! empty( $instance['style'] ) && 'grid' == $instance['style'] ) : ?>
<div class="product-loop-content content-grid">
<?php
$shortcode = '[best_selling_products limit="' . $instance['posts_per_page'] . '" orderby="date" columns="' . $instance['columns'] . '"]';
echo do_shortcode( $shortcode );
?>
</div>
<?php else : ?>
<div class="product-loop-content content-carousel product-pre-load" data-columns="<?php echo esc_attr( $instance['columns'] ); ?>">
<div class="load-animation"></div>
<?php
$shortcode = '[best_selling_products limit="' . $instance['posts_per_page'] . '" orderby="date" columns="1"]';
echo do_shortcode( $shortcode )
?>
</div>
<?php endif;
echo $args['after_widget'];
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = esc_html( $new_instance['title'] );
$instance['title_url'] = esc_html( $new_instance['title_url'] );
$instance['posts_per_page'] = absint( esc_attr( $new_instance['posts_per_page'] ) );
$instance['columns'] = absint( esc_attr( $new_instance['columns'] ) );
$instance['style'] = esc_attr( $new_instance['style'] );
return $instance;
}
function form( $instance ) {
$defaults = array(
'title' => esc_html__( 'Best Selling Products', 'glaza-core' ),
'title_url' => '',
'posts_per_page' => 8,
'columns' => 4,
'style' => 'carousel'
);
$instance = wp_parse_args( (array) $instance, $defaults ); ?>
<h3 class="glaza-wh"><?php esc_html_e( 'Header Options', 'glaza-core' ) ?></h3>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><strong><?php esc_html_e( 'Title:', 'glaza-core' ) ?></strong></label>
<input type="text" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" value="<?php if ( ! empty( $instance['title'] ) ) echo esc_attr( $instance['title'] ); ?>"/>
</p>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'title_url' ) ); ?>"><?php esc_html_e( 'Title URL (optional):', 'glaza-core' ) ?></label>
<input type="text" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title_url' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title_url' ) ); ?>" value="<?php if ( ! empty( $instance['title_url'] ) ) echo esc_html( $instance['title_url'] ); ?>"/>
</p>
<h3 class="glaza-wh"><?php esc_html_e( 'Filter Options', 'glaza-core' ) ?></h3>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'posts_per_page' ) ); ?>"><strong><?php esc_html_e( 'Total Products:', 'glaza-core' ) ?></strong></label>
<input type="text" class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'posts_per_page' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'posts_per_page' ) ); ?>" value="<?php if ( ! empty( $instance['posts_per_page'] ) ) echo esc_attr( $instance['posts_per_page'] ); ?>"/>
</p>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'columns' ) ); ?>"><strong><?php esc_html_e( 'Columns:', 'glaza-core' ); ?></strong></label>
<select class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'columns' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'columns' ) ); ?>">
<option value="2" <?php if ( ! empty( $instance['columns'] ) && $instance['columns'] == '2' ) echo "selected=\"selected\""; else echo ""; ?>><?php esc_html_e( '2', 'glaza-core' ); ?></option>
<option value="3" <?php if ( ! empty( $instance['columns'] ) && $instance['columns'] == '3' ) echo "selected=\"selected\""; else echo ""; ?>><?php esc_html_e( '3', 'glaza-core' ); ?></option>
<option value="4" <?php if ( ! empty( $instance['columns'] ) && $instance['columns'] == '4' ) echo "selected=\"selected\""; else echo ""; ?>><?php esc_html_e( '4', 'glaza-core' ); ?></option>
<option value="5" <?php if ( ! empty( $instance['columns'] ) && $instance['columns'] == '5' ) echo "selected=\"selected\""; else echo ""; ?>><?php esc_html_e( '5', 'glaza-core' ); ?></option>
</select>
</p>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'style' ) ); ?>"><strong><?php esc_html_e( 'Block Layout:', 'glaza-core' ); ?></strong></label>
<select class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'style' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'style' ) ); ?>">
<option value="carousel" <?php if ( ! empty( $instance['style'] ) && $instance['style'] == 'carousel' ) echo "selected=\"selected\""; else echo ""; ?>><?php esc_html_e( 'Carousel', 'glaza-core' ); ?></option>
<option value="grid" <?php if ( ! empty( $instance['style'] ) && $instance['style'] == 'grid' ) echo "selected=\"selected\""; else echo ""; ?>><?php esc_html_e( 'Grid', 'glaza-core' ); ?></option>
</select>
</p>
<?php
}
}
endif;