芝麻web文件管理V1.00
编辑当前文件:/home/royashxg/www/wp-content/plugins/elementor-pro/modules/woocommerce/widgets/product-related.php
start_controls_section( 'section_related_products_content', [ 'label' => esc_html__( 'Related Products', 'elementor-pro' ), ] ); $this->add_control( 'posts_per_page', [ 'label' => esc_html__( 'Products Per Page', 'elementor-pro' ), 'type' => Controls_Manager::NUMBER, 'default' => 4, 'range' => [ 'px' => [ 'max' => 20, ], ], ] ); $this->add_columns_responsive_control(); $this->add_control( 'orderby', [ 'label' => esc_html__( 'Order By', 'elementor-pro' ), 'type' => Controls_Manager::SELECT, 'default' => 'date', 'options' => [ 'date' => esc_html__( 'Date', 'elementor-pro' ), 'title' => esc_html__( 'Title', 'elementor-pro' ), 'price' => esc_html__( 'Price', 'elementor-pro' ), 'popularity' => esc_html__( 'Popularity', 'elementor-pro' ), 'rating' => esc_html__( 'Rating', 'elementor-pro' ), 'rand' => esc_html__( 'Random', 'elementor-pro' ), 'menu_order' => esc_html__( 'Menu Order', 'elementor-pro' ), ], ] ); $this->add_control( 'order', [ 'label' => esc_html__( 'Order', 'elementor-pro' ), 'type' => Controls_Manager::SELECT, 'default' => 'desc', 'options' => [ 'asc' => esc_html__( 'ASC', 'elementor-pro' ), 'desc' => esc_html__( 'DESC', 'elementor-pro' ), ], ] ); $this->end_controls_section(); parent::register_controls(); $this->start_injection( [ 'at' => 'before', 'of' => 'section_design_box', ] ); $this->start_controls_section( 'section_heading_style', [ 'label' => esc_html__( 'Heading', 'elementor-pro' ), 'tab' => Controls_Manager::TAB_STYLE, ] ); $this->add_control( 'show_heading', [ 'label' => esc_html__( 'Heading', 'elementor-pro' ), 'type' => Controls_Manager::SWITCHER, 'label_off' => esc_html__( 'Hide', 'elementor-pro' ), 'label_on' => esc_html__( 'Show', 'elementor-pro' ), 'default' => 'yes', 'return_value' => 'yes', 'prefix_class' => 'show-heading-', ] ); $this->add_control( 'heading_color', [ 'label' => esc_html__( 'Color', 'elementor-pro' ), 'type' => Controls_Manager::COLOR, 'global' => [ 'default' => Global_Colors::COLOR_PRIMARY, ], 'selectors' => [ '.woocommerce {{WRAPPER}}.elementor-wc-products .products > h2' => 'color: {{VALUE}}', ], 'condition' => [ 'show_heading!' => '', ], ] ); $this->add_group_control( Group_Control_Typography::get_type(), [ 'name' => 'heading_typography', 'global' => [ 'default' => Global_Typography::TYPOGRAPHY_PRIMARY, ], 'selector' => '.woocommerce {{WRAPPER}}.elementor-wc-products .products > h2', 'condition' => [ 'show_heading!' => '', ], ] ); $this->add_responsive_control( 'heading_text_align', [ 'label' => esc_html__( 'Text Align', 'elementor-pro' ), 'type' => Controls_Manager::CHOOSE, 'options' => [ 'left' => [ 'title' => esc_html__( 'Left', 'elementor-pro' ), 'icon' => 'eicon-text-align-left', ], 'center' => [ 'title' => esc_html__( 'Center', 'elementor-pro' ), 'icon' => 'eicon-text-align-center', ], 'right' => [ 'title' => esc_html__( 'Right', 'elementor-pro' ), 'icon' => 'eicon-text-align-right', ], ], 'selectors' => [ '.woocommerce {{WRAPPER}}.elementor-wc-products .products > h2' => 'text-align: {{VALUE}}', ], 'condition' => [ 'show_heading!' => '', ], ] ); $this->add_responsive_control( 'heading_spacing', [ 'label' => esc_html__( 'Spacing', 'elementor-pro' ), 'type' => Controls_Manager::SLIDER, 'size_units' => [ 'px', 'em', 'rem', 'custom' ], 'selectors' => [ '.woocommerce {{WRAPPER}}.elementor-wc-products .products > h2' => 'margin-bottom: {{SIZE}}{{UNIT}}', ], 'condition' => [ 'show_heading!' => '', ], ] ); $this->end_controls_section(); $this->end_injection(); } protected function render() { global $product; $product = $this->get_product(); if ( ! $product ) { return; } $settings = $this->get_settings_for_display(); // Add a wrapper class to the Add to Cart & View Items elements if the automically_align_buttons switch has been selected. if ( 'yes' === $settings['automatically_align_buttons'] ) { add_filter( 'woocommerce_loop_add_to_cart_link', [ $this, 'add_to_cart_wrapper' ], 10, 1 ); } $args = [ 'posts_per_page' => 4, 'columns' => 4, 'orderby' => $settings['orderby'], 'order' => $settings['order'], ]; if ( ! empty( $settings['posts_per_page'] ) ) { $args['posts_per_page'] = $settings['posts_per_page']; } if ( ! empty( $settings['columns'] ) ) { $args['columns'] = $settings['columns']; } $args = array_map( 'sanitize_text_field', $args ); // Get visible related products then sort them at random. $args['related_products'] = array_filter( array_map( 'wc_get_product', wc_get_related_products( $product->get_id(), $args['posts_per_page'], $product->get_upsell_ids() ) ), 'wc_products_array_filter_visible' ); // Handle orderby. $args['related_products'] = wc_products_array_orderby( $args['related_products'], $args['orderby'], $args['order'] ); ob_start(); wc_get_template( 'single-product/related.php', $args ); $related_products_html = ob_get_clean(); if ( $related_products_html ) { $related_products_html = str_replace( '