start_controls_section('section_settings', array('label' => __('设置', 'yoone-product-bundles'))); $this->add_control('use_current_product', array( 'label' => __('使用当前产品页面', 'yoone-product-bundles'), 'type' => \Elementor\Controls_Manager::SWITCHER, 'label_on' => __('是', 'yoone-product-bundles'), 'label_off' => __('否', 'yoone-product-bundles'), 'return_value' => 'yes', 'default' => 'yes', )); $this->add_control('product_id', array( 'label' => __('指定产品ID(Mix and Match 类型)', 'yoone-product-bundles'), 'type' => \Elementor\Controls_Manager::NUMBER, 'default' => 0, 'condition' => array('use_current_product!' => 'yes'), )); $this->end_controls_section(); } protected function render() { $settings = $this->get_settings_for_display(); $use_current = isset($settings['use_current_product']) && $settings['use_current_product'] === 'yes'; $product_id = absint(isset($settings['product_id']) ? $settings['product_id'] : 0); // 确定产品对象 $product = null; if ($use_current && is_singular('product')) { global $post; if ($post) $product = wc_get_product($post->ID); } elseif ($product_id > 0) { $product = wc_get_product($product_id); } if (! $product || $product->get_type() !== Yoone_Product_Bundles::TYPE) { echo '