product-title.php
137 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Elementor; |
| 4 | |
| 5 | defined('ABSPATH') || exit; |
| 6 | |
| 7 | use ShopEngine\Core\Template_Cpt; |
| 8 | use ShopEngine\Widgets\Products; |
| 9 | |
| 10 | class ShopEngine_Product_Title extends \ShopEngine\Base\Widget |
| 11 | { |
| 12 | |
| 13 | public function config() { |
| 14 | return new ShopEngine_Product_Title_Config(); |
| 15 | } |
| 16 | |
| 17 | protected function register_controls() { |
| 18 | |
| 19 | $this->start_controls_section( |
| 20 | 'shopengine_section_product_title_style', |
| 21 | array( |
| 22 | 'label' => esc_html__('Product Title', 'shopengine'), |
| 23 | 'tab' => Controls_Manager::TAB_STYLE, |
| 24 | ) |
| 25 | ); |
| 26 | |
| 27 | $this->add_control( |
| 28 | 'shopengine_product_title_header_size', |
| 29 | [ |
| 30 | 'label' => esc_html__('HTML Tag', 'shopengine'), |
| 31 | 'type' => Controls_Manager::SELECT, |
| 32 | 'options' => [ |
| 33 | 'h1' => 'H1', |
| 34 | 'h2' => 'H2', |
| 35 | 'h3' => 'H3', |
| 36 | 'h4' => 'H4', |
| 37 | 'h5' => 'H5', |
| 38 | 'h6' => 'H6', |
| 39 | 'div' => 'div', |
| 40 | 'span' => 'span', |
| 41 | 'p' => 'p', |
| 42 | ], |
| 43 | 'default' => 'h1', |
| 44 | 'selectors' => [ |
| 45 | '{{WRAPPER}} .product-title' => 'margin: 0; padding: 0;', |
| 46 | ], |
| 47 | ] |
| 48 | ); |
| 49 | |
| 50 | $this->add_responsive_control( |
| 51 | 'shopengine_product_title_align', |
| 52 | \ShopEngine\Utils\Controls_Helper::get_alignment_conf() |
| 53 | ); |
| 54 | |
| 55 | $this->add_control( |
| 56 | 'shopengine_product_title_product_title_color', |
| 57 | [ |
| 58 | 'label' => esc_html__('Title Color', 'shopengine'), |
| 59 | 'type' => Controls_Manager::COLOR, |
| 60 | 'default' => '#000000', |
| 61 | 'alpha' => false, |
| 62 | 'selectors' => [ |
| 63 | '{{WRAPPER}} .product-title' => 'color: {{VALUE}};', |
| 64 | ], |
| 65 | ] |
| 66 | ); |
| 67 | |
| 68 | $this->add_group_control( |
| 69 | Group_Control_Typography::get_type(), |
| 70 | array( |
| 71 | 'name' => 'shopengine_product_title_typography', |
| 72 | 'label' => esc_html__('Typography', 'shopengine'), |
| 73 | 'selector' => '{{WRAPPER}} .product-title', |
| 74 | 'exclude' => ['text_decoration'], |
| 75 | 'fields_options' => [ |
| 76 | 'typography' => [ |
| 77 | 'default' => 'custom', |
| 78 | ], |
| 79 | 'font_weight' => [ |
| 80 | 'default' => '700', |
| 81 | ], |
| 82 | 'font_size' => [ |
| 83 | 'label' => esc_html__('Font Size (px)', 'shopengine'), |
| 84 | 'default' => [ |
| 85 | 'size' => '24', |
| 86 | 'unit' => 'px' |
| 87 | ], |
| 88 | 'size_units' => ['px'], |
| 89 | ], |
| 90 | 'text_transform' => [ |
| 91 | 'default' => 'uppercase', |
| 92 | ], |
| 93 | 'line_height' => [ |
| 94 | 'label' => esc_html__('Line Height (px)', 'shopengine'), |
| 95 | 'default' => [ |
| 96 | 'size' => '24', |
| 97 | 'unit' => 'px' |
| 98 | ], |
| 99 | 'size_units' => ['px'], |
| 100 | 'tablet_default' => [ |
| 101 | 'unit' => 'px', |
| 102 | ], |
| 103 | 'mobile_default' => [ |
| 104 | 'unit' => 'px', |
| 105 | ], |
| 106 | ], |
| 107 | 'letter_spacing' => [ |
| 108 | 'label' => esc_html__('Letter Spacing (px)', 'shopengine'), |
| 109 | 'default' => [ |
| 110 | 'size' => '0.1', |
| 111 | ], |
| 112 | 'size_units' => ['px'], |
| 113 | ], |
| 114 | ], |
| 115 | ) |
| 116 | ); |
| 117 | |
| 118 | $this->end_controls_section(); |
| 119 | |
| 120 | } |
| 121 | |
| 122 | protected function screen() { |
| 123 | |
| 124 | $settings = $this->get_settings_for_display(); |
| 125 | |
| 126 | $post_type = get_post_type(); |
| 127 | |
| 128 | $product = Products::instance()->get_product($post_type); |
| 129 | |
| 130 | echo sprintf( |
| 131 | '<div class="shopengine-product-title"><%1$s class="product-title">%2$s</%1$s></div>', |
| 132 | $settings['shopengine_product_title_header_size'], |
| 133 | get_the_title($product->get_id()) |
| 134 | ); |
| 135 | } |
| 136 | } |
| 137 |