start_controls_section( 'section_query', [ 'label' => __( 'Query', 'admore-widgets-suite' ), ] ); $this->add_control( 'posts_per_page', [ 'label' => __( 'Products Per Page', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::NUMBER, 'default' => 6, 'min' => 1, 'max' => 48, ] ); $this->add_control( 'orderby', [ 'label' => __( 'Order By', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::SELECT, 'default' => 'date', 'options' => [ 'date' => __( 'Date', 'admore-widgets-suite' ), 'title' => __( 'Title', 'admore-widgets-suite' ), 'price' => __( 'Price', 'admore-widgets-suite' ), 'popularity' => __( 'Popularity', 'admore-widgets-suite' ), 'rating' => __( 'Rating', 'admore-widgets-suite' ), 'rand' => __( 'Random', 'admore-widgets-suite' ), ], ] ); $this->add_control( 'order', [ 'label' => __( 'Order', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::SELECT, 'default' => 'DESC', 'options' => [ 'ASC' => __('ASC','admore-widgets-suite'), 'DESC' => __('DESC','admore-widgets-suite') ], ] ); $this->add_control( 'product_type', [ 'label' => __( 'Product Type', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::SELECT, 'default' => 'all', 'options' => [ 'all' => __( 'All', 'admore-widgets-suite' ), 'featured' => __( 'Featured', 'admore-widgets-suite' ), 'sale' => __( 'On Sale', 'admore-widgets-suite' ), ], ] ); $this->add_control( 'category', [ 'label' => __( 'Category Slug(s)', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::TEXT, 'placeholder' => __( 'clothing, accessories', 'admore-widgets-suite' ), 'description' => __( 'Comma-separated category slugs.', 'admore-widgets-suite' ), 'dynamic' => [ 'active' => true ], ] ); $this->add_control( 'pagination_type', [ 'label' => __( 'Pagination', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::SELECT, 'default' => 'none', 'options' => [ 'none' => __( 'None', 'admore-widgets-suite' ), 'load_more' => __( 'Load More Button', 'admore-widgets-suite' ), ], 'separator' => 'before', ] ); $this->add_control( 'load_more_text', [ 'label' => __( 'Load More Text', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::TEXT, 'default' => __( 'Load More', 'admore-widgets-suite' ), 'condition' => [ 'pagination_type' => 'load_more' ], ] ); $this->end_controls_section(); /* ── Layout ── */ $this->start_controls_section( 'section_layout', [ 'label' => __( 'Layout', 'admore-widgets-suite' ), ] ); $this->add_control( 'show_filter_tabs', [ 'label' => __( 'Category Filter Tabs', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::SWITCHER, 'default' => '', 'return_value' => 'yes', 'description' => __( 'Show AJAX category filter tabs above the products grid.', 'admore-widgets-suite' ), 'separator' => 'before', ] ); $this->add_control( 'filter_all_text', [ 'label' => __( 'All Tab Label', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::TEXT, 'default' => __( 'All', 'admore-widgets-suite' ), 'condition' => [ 'show_filter_tabs' => 'yes' ], ] ); $this->add_responsive_control( 'columns', [ 'label' => __( 'Columns', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::SELECT, 'default' => '3', 'tablet_default' => '2', 'mobile_default' => '1', 'options' => [ '1'=>'1','2'=>'2','3'=>'3','4'=>'4' ], 'selectors' => [ '{{WRAPPER}} .eppro-wp-grid' => 'grid-template-columns: repeat({{VALUE}}, 1fr);' ], ] ); $this->add_control( 'show_rating', [ 'label' => __( 'Show Rating', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::SWITCHER, 'default' => 'yes', 'return_value' => 'yes', ] ); $this->add_control( 'show_add_to_cart', [ 'label' => __( 'Show Add to Cart', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::SWITCHER, 'default' => 'yes', 'return_value' => 'yes', ] ); $this->add_control( 'show_badge', [ 'label' => __( 'Show Sale / New Badge', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::SWITCHER, 'default' => 'yes', 'return_value' => 'yes', ] ); $this->add_control( 'show_oos_badge', [ 'label' => __( 'Show Out of Stock Badge', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::SWITCHER, 'default' => 'yes', 'return_value' => 'yes', ] ); $this->add_control( 'oos_badge_text', [ 'label' => __( 'Out of Stock Text', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::TEXT, 'default' => __( 'Out of Stock', 'admore-widgets-suite' ), 'condition' => [ 'show_oos_badge' => 'yes' ], ] ); $this->add_control( 'show_quick_view', [ 'label' => __( 'Show Quick View Button', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::SWITCHER, 'default' => 'yes', 'return_value' => 'yes', ] ); $this->end_controls_section(); /* ── Style ── */ $this->start_controls_section( 'section_style', [ 'label' => __( 'Cards', 'admore-widgets-suite' ), 'tab' => \Elementor\Controls_Manager::TAB_STYLE, ] ); $this->add_control( 'card_bg', [ 'label' => __( 'Card Background', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::COLOR, 'default' => '#ffffff', 'selectors' => [ '{{WRAPPER}} .eppro-wp-card' => 'background: {{VALUE}};' ], ] ); $this->add_control( 'card_radius', [ 'label' => __( 'Border Radius', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::SLIDER, 'range' => [ 'px' => [ 'min' => 0, 'max' => 30 ] ], 'default' => [ 'size' => 10 ], 'selectors' => [ '{{WRAPPER}} .eppro-wp-card' => 'border-radius: {{SIZE}}px; overflow: hidden;' ], ] ); $this->add_control( 'img_height', [ 'label' => __( 'Image Height', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::SLIDER, 'range' => [ 'px' => [ 'min' => 80, 'max' => 500 ] ], 'default' => [ 'size' => 220 ], 'selectors' => [ '{{WRAPPER}} .eppro-wp-thumb img' => 'height: {{SIZE}}px;' ], ] ); $this->add_control( 'sale_badge_color', [ 'label' => __( 'Sale Badge Color', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::COLOR, 'default' => '#ef4444', 'selectors' => [ '{{WRAPPER}} .eppro-wp-badge--sale' => 'background-color: {{VALUE}};' ], 'condition' => [ 'show_badge' => 'yes' ], 'separator' => 'before', ] ); $this->add_control( 'oos_badge_color', [ 'label' => __( 'OOS Badge Color', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::COLOR, 'default' => '#64748b', 'selectors' => [ '{{WRAPPER}} .eppro-wp-badge--oos' => 'background-color: {{VALUE}};' ], 'condition' => [ 'show_oos_badge' => 'yes' ], ] ); $this->add_control( 'price_color', [ 'label' => __( 'Price Color', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::COLOR, 'default' => EPPRO_Elementor_Helper::brand_color(), 'selectors' => [ '{{WRAPPER}} .eppro-wp-price' => 'color: {{VALUE}};' ], ] ); $this->add_control( 'btn_bg', [ 'label' => __( 'Add to Cart Color', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::COLOR, 'default' => EPPRO_Elementor_Helper::brand_color(), 'selectors' => [ '{{WRAPPER}} .eppro-wp-atc' => 'background: {{VALUE}}; border-color: {{VALUE}};' ], ] ); $this->add_control( 'product_name_color', [ 'label' => __( 'Product Name Color', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::COLOR, 'separator' => 'before', 'selectors' => [ '{{WRAPPER}} .eppro-wp-name' => 'color: {{VALUE}};' ], ] ); $this->add_group_control( \Elementor\Group_Control_Typography::get_type(), [ 'name' => 'product_name_typo', 'selector' => '{{WRAPPER}} .eppro-wp-name', ] ); $this->add_control( 'card_hover_bg', [ 'label' => __( 'Card Hover Background', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::COLOR, 'separator' => 'before', 'selectors' => [ '{{WRAPPER}} .eppro-wp-card:hover' => 'background: {{VALUE}};' ], ] ); $this->add_group_control( \Elementor\Group_Control_Box_Shadow::get_type(), [ 'name' => 'card_shadow', 'selector' => '{{WRAPPER}} .eppro-wp-card', ] ); $this->add_responsive_control( 'card_body_padding', [ 'label' => __( 'Card Body Padding', 'admore-widgets-suite' ), 'type' => \Elementor\Controls_Manager::DIMENSIONS, 'size_units' => [ 'px', 'em' ], 'default' => [ 'top'=>'14','right'=>'14','bottom'=>'14','left'=>'14','unit'=>'px' ], 'selectors' => [ '{{WRAPPER}} .eppro-wp-body' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ], 'separator' => 'before', ] ); $this->end_controls_section(); $this->eppro_register_entrance_animation_controls(); } // ========================================================================= // Query & card markup — shared by render() and the Load More AJAX handler // ========================================================================= /** * WP_Query arguments for one page of products. * * @param array $s Widget settings. * @param int $paged 1-based page number. */ private function get_query_args( array $s, int $paged = 1 ): array { $num = max( 1, min( 48, intval( $s['posts_per_page'] ?? 6 ) ) ); $orderby = sanitize_key( $s['orderby'] ?? 'date' ); $order = strtoupper( sanitize_key( $s['order'] ?? 'DESC' ) ); $ptype = $s['product_type'] ?? 'all'; $cats = array_values( array_filter( array_map( 'sanitize_title', array_map( 'trim', explode( ',', (string) ( $s['category'] ?? '' ) ) ) ) ) ); if ( ! in_array( $orderby, [ 'date', 'title', 'price', 'popularity', 'rating', 'rand' ], true ) ) { $orderby = 'date'; } if ( ! in_array( $order, [ 'ASC', 'DESC' ], true ) ) { $order = 'DESC'; } $args = [ 'post_type' => 'product', 'post_status' => 'publish', 'posts_per_page' => $num, 'paged' => max( 1, $paged ), 'order' => $order, ]; if ( 'price' === $orderby ) { $args['orderby'] = 'meta_value_num'; $args['meta_key'] = '_price'; // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- Sorting by price requires the meta key. } elseif ( 'popularity' === $orderby ) { $args['orderby'] = 'meta_value_num'; $args['meta_key'] = 'total_sales'; // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- Sorting by sales requires the meta key. } elseif ( 'rating' === $orderby ) { $args['orderby'] = 'meta_value_num'; $args['meta_key'] = '_wc_average_rating'; // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- Sorting by rating requires the meta key. } else { $args['orderby'] = $orderby; } // Respect WooCommerce catalog visibility (hidden products, hidden out-of-stock items). $tax_query = []; $visibility = function_exists( 'wc_get_product_visibility_term_ids' ) ? wc_get_product_visibility_term_ids() : []; $hidden = []; if ( ! empty( $visibility['exclude-from-catalog'] ) ) { $hidden[] = $visibility['exclude-from-catalog']; } if ( ! empty( $visibility['outofstock'] ) && 'yes' === get_option( 'woocommerce_hide_out_of_stock_items' ) ) { $hidden[] = $visibility['outofstock']; } if ( $hidden ) { $tax_query[] = [ 'taxonomy' => 'product_visibility', 'field' => 'term_taxonomy_id', 'terms' => $hidden, 'operator' => 'NOT IN' ]; } if ( 'featured' === $ptype ) { // WooCommerce 3.0+ stores "featured" as a product_visibility term, not post meta. $tax_query[] = [ 'taxonomy' => 'product_visibility', 'field' => 'name', 'terms' => 'featured' ]; } elseif ( 'sale' === $ptype && function_exists( 'wc_get_product_ids_on_sale' ) ) { $args['post__in'] = array_merge( [ 0 ], wc_get_product_ids_on_sale() ); } if ( $cats ) { $tax_query[] = [ 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => $cats ]; } if ( $tax_query ) { $args['tax_query'] = array_merge( [ 'relation' => 'AND' ], $tax_query ); // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query -- Category / visibility filters. } return $args; } /** Print the card for the current product in the loop. */ private function render_card( array $s ): void { $product = wc_get_product( get_the_ID() ); if ( ! $product ) return; $is_sale = $product->is_on_sale(); $is_new = ( time() - (int) get_post_time( 'U', true ) ) < 30 * DAY_IN_SECONDS; $is_oos = ! $product->is_in_stock(); $card_terms = wp_get_post_terms( get_the_ID(), 'product_cat', [ 'fields' => 'slugs' ] ); $card_terms = is_array( $card_terms ) ? $card_terms : []; $show_oos_badge = 'yes' === ( $s['show_oos_badge'] ?? '' ); $oos_badge_text = $s['oos_badge_text'] ?? __( 'Out of Stock', 'admore-widgets-suite' ); ?>
' . esc_html__( 'WooCommerce Required', 'admore-widgets-suite' ) . '
' . esc_html__( 'Please install and activate WooCommerce to use this widget.', 'admore-widgets-suite' ) . '
' . esc_html__( 'WooCommerce Products', 'admore-widgets-suite' ) . '
' . esc_html__( 'No products found. Adjust the query settings.', 'admore-widgets-suite' ) . '