'wp_commerce_new_arrival_products', 'description' => __( 'Display numbers of New Arrival products from selective categories.', 'wp-commerce' ), 'customize_selective_refresh' => true, ); parent::__construct( 'wp_commerce_new_arrival_products', __( 'WP Commerce: New Arrival Products', 'wp-commerce' ), $widget_ops ); } /** * Helper function that holds widget fields * Array is used in update and form functions */ private function widget_fields() { $fields = array( 'section_post_count' => array( 'wp_commerce_widgets_name' => 'section_post_count', 'wp_commerce_widgets_title' => __( 'Product Count', 'wp-commerce' ), 'wp_commerce_widgets_default' => 10, 'wp_commerce_widgets_field_type' => 'number' ), ); return $fields; } /** * Front-end display of widget. * * @see WP_Widget::widget() * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ public function widget( $args, $instance ) { extract( $args ); if( empty( $instance ) ) { return ; } $wp_commerce_product_count = empty( $instance['section_post_count'] ) ? 10 : $instance['section_post_count']; $new_arrival_args = array( 'post_type' => 'product', 'posts_per_page' => absint( $wp_commerce_product_count ), 'stock' => 1, 'orderby' =>'date', 'order' => 'DESC' ); $new_arrival_query = new WP_Query( $new_arrival_args ); $total_post = $new_arrival_query->post_count; ?> have_posts() ) { while ( $new_arrival_query->have_posts() ) { $new_arrival_query->the_post();?>
get_id(), 'product_cat' ); if ( $terms && ! is_wp_error( $terms ) ) {?> name);?>

widget_fields(); // Loop through fields foreach ( $widget_fields as $widget_field ) { extract( $widget_field ); // Use helper function to get updated field values $instance[$wp_commerce_widgets_name] = wp_commerce_widgets_updated_field_value( $widget_field, $new_instance[$wp_commerce_widgets_name] ); } return $instance; } /** * Back-end widget form. * * @see WP_Widget::form() * * @param array $instance Previously saved values from database. * * @uses wp_commerce_widgets_show_widget_field() defined in es-widget-fields.php */ public function form( $instance ) { $widget_fields = $this->widget_fields(); // Loop through fields foreach ( $widget_fields as $widget_field ) { // Make array elements available as variables extract( $widget_field ); if ( empty( $instance ) && isset( $wp_commerce_widgets_default ) ) { $wp_commerce_widgets_field_value = $wp_commerce_widgets_default; } elseif( empty( $instance ) ) { $wp_commerce_widgets_field_value = ''; } else { $wp_commerce_widgets_field_value = wp_kses_post( $instance[$wp_commerce_widgets_name] ); } //$wp_commerce_widgets_field_value = !empty( $instance[$wp_commerce_widgets_name] ) ? wp_kses_post( $instance[$wp_commerce_widgets_name] ) : ''; wp_commerce_widgets_show_widget_field( $this, $widget_field, $wp_commerce_widgets_field_value ); } } }