File: /home/atiscoir/public_html/wp-content/themes/servin/inc/elements/shop/basket.php
<?php
namespace Elementor;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class TMT_Basket extends Widget_Base {
public function get_name() {
return 'tmt-basket';
}
public function get_title() {
return __( 'Basket Shop', text_domain );
}
public function get_icon() {
return 'eicon-sync';
}
public function get_categories() {
return [ 'shop_servin' ];
}
public function get_keywords() {
return [ 'shop', 'basket', 'form'];
}
protected function register_controls() {
$this->register_general_content_controls();
$this->register_general_btn_controls();
$this->register_general_basket_style_controls();
$this->register_general_btn_style_controls();
}
protected function register_general_content_controls() {
$this->start_controls_section(
'section_setting',
[
'label' => __( 'Login', text_domain ),
]
);
$this->add_responsive_control(
'align',
[
'label' => __( 'Alignment', text_domain ),
'type' => Controls_Manager::CHOOSE,
'options' => [
'left' => [
'title' => __( 'Left', text_domain ),
'icon' => 'eicon-text-align-left',
],
'center' => [
'title' => __( 'Center', text_domain ),
'icon' => 'eicon-text-align-center',
],
'right' => [
'title' => __( 'Right', text_domain ),
'icon' => 'eicon-text-align-right',
],
],
'default' => 'center',
'toggle' => true,
]
);
$this->end_controls_section();
}
protected function register_general_btn_controls() {
$this->start_controls_section(
'section_btn',
[
'label' => __( 'Button', text_domain ),
]
);
$this->add_control(
'btn_text',
[
'label' => __( 'Text', text_domain ),
'type' => Controls_Manager::TEXT,
'placeholder' => __( 'Type your text here', text_domain ),
]
);
$this->add_control(
'btn_align',
[
'label' => __( 'Alignment', text_domain ),
'type' => Controls_Manager::CHOOSE,
'options' => [
'left' => [
'title' => __( 'Left', text_domain ),
'icon' => 'eicon-text-align-left',
],
'right' => [
'title' => __( 'Right', text_domain ),
'icon' => 'eicon-text-align-right',
],
],
'default' => 'right',
'toggle' => true,
]
);
$this->add_control(
'btn_icon',
[
'label' => __( 'Icon', text_domain ),
'type' => Controls_Manager::ICONS,
'default' => [
'value' => 'fas fa-shopping-cart',
'library' => 'solid',
],
]
);
$this->add_control(
'show_count_cart',
[
'label' => __( 'Show Count Cart', text_domain ),
'type' => Controls_Manager::SWITCHER,
'label_on' => __( 'Show', text_domain ),
'label_off' => __( 'Hide', text_domain ),
'return_value' => 'yes',
'default' => 'yes',
]
);
$this->end_controls_section();
}
protected function register_general_basket_style_controls() {
$this->start_controls_section(
'section_style',
[
'label' => __( 'Style', text_domain ),
'tab' => Controls_Manager::TAB_STYLE,
]
);
$this->add_responsive_control(
'dropdown_width',
[
'label' => __( 'DropDown Width', text_domain ),
'type' => Controls_Manager::SLIDER,
'size_units' => [ 'px', '%' ],
'range' => [
'px' => [
'min' => 0,
'max' => 1000,
'step' => 10,
],
'%' => [
'min' => 0,
'max' => 100,
],
],
'default' => [
'unit' => 'px',
'size' => 300,
],
'selectors' => [
'{{WRAPPER}} .drop-down-offcanvas > div' => 'width: {{SIZE}}{{UNIT}};',
],
]
);
$this->add_control(
'content_bg_color',
[
'label' => __( 'Background Color', text_domain ),
'type' => Controls_Manager::COLOR,
'default' => '#FFF',
'selectors' => [
'{{WRAPPER}} .drop-down-offcanvas > div' => 'background-color: {{VALUE}}',
],
]
);
$this->add_control(
'content_margin',
[
'label' => __( 'Margin', text_domain ),
'type' => Controls_Manager::DIMENSIONS,
'size_units' => [ 'px', '%', 'em' ],
'selectors' => [
'{{WRAPPER}} .drop-down-offcanvas > div' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
],
]
);
$this->add_control(
'content_padding',
[
'label' => __( 'Padding', text_domain ),
'type' => Controls_Manager::DIMENSIONS,
'size_units' => [ 'px', '%', 'em' ],
'default' => [
'top' => '15',
'right' => '15',
'bottom' => '15',
'left' => '15',
'unit' => 'px',
],
'selectors' => [
'{{WRAPPER}} .drop-down-offcanvas > div' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
],
]
);
$this->add_control(
'content_border_radius',
[
'label' => __( 'Border Radius', text_domain ),
'type' => Controls_Manager::DIMENSIONS,
'size_units' => [ 'px', '%', 'em' ],
'selectors' => [
'{{WRAPPER}} .shopping-cart-content' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
],
]
);
$this->add_group_control(
Group_Control_Border::get_type(),
[
'name' => 'content_border',
'label' => __( 'Border', text_domain ),
'selector' => '{{WRAPPER}} .shopping-cart-content',
]
);
$this->add_group_control(
Group_Control_Box_Shadow::get_type(),
[
'name' => 'content_box_shadow',
'label' => __( 'Box Shadow', text_domain ),
'selector' => '{{WRAPPER}} .shopping-cart-content',
]
);
$this->add_control(
'cart_product_title',
[
'label' => __( 'Title', text_domain ),
'type' => Controls_Manager::COLOR,
'default' => '#eead16',
'selectors' => [
'{{WRAPPER}} .mini_cart_item a' => 'color: {{VALUE}}',
],
]
);
$this->add_control(
'cart_product_price',
[
'label' => __( 'Price', text_domain ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .quantity' => 'color: {{VALUE}}',
],
]
);
$this->add_control(
'cart_product_remove_icon',
[
'label' => __( 'Icon', text_domain ),
'type' => Controls_Manager::COLOR,
'default' => '#eead16',
'selectors' => [
'{{WRAPPER}} .mini_cart_item a.remove_from_cart_button' => 'color: {{VALUE}}',
],
]
);
$this->add_control(
'cart_product_total_price',
[
'label' => __( 'Total Price', text_domain ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .total' => 'color: {{VALUE}}',
],
]
);
$this->add_control(
'cart_product_separator',
[
'label' => __( 'Separator', text_domain ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .total' => 'border-color: {{VALUE}}',
],
]
);
$this->add_control(
'buttons_options',
[
'label' => __( 'Buttons', text_domain ),
'type' => Controls_Manager::HEADING,
'separator' => 'before',
]
);
$this->start_controls_tabs('style_btn_tabs');
$this->start_controls_tab('style_btn_normal_tab', ['label' => __( 'Normal', text_domain ),]);
$this->add_control(
'cart_total_options',
[
'label' => __( 'Cart Total ', text_domain ),
'type' => Controls_Manager::HEADING,
]
);
$this->add_control(
'color_cart_total',
[
'label' => __( 'Color', text_domain ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .woocommerce-mini-cart__total' => 'color: {{VALUE}}',
],
]
);
$this->add_control(
'bg_color_cart_total',
[
'label' => __( 'Background Color', text_domain ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .woocommerce-mini-cart__total' => 'background-color: {{VALUE}}',
],
]
);
$this->add_control(
'options_btn_forward',
[
'label' => __( 'Wc Forward', text_domain ),
'type' => Controls_Manager::HEADING,
'separator' => 'before',
]
);
$this->add_control(
'color_btn_forward',
[
'label' => __( 'Color', text_domain ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .buttons .wc-forward' => 'color: {{VALUE}}',
],
]
);
$this->add_control(
'bg_color_btn_forward',
[
'label' => __( 'Background Color', text_domain ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .buttons .wc-forward' => 'background-color: {{VALUE}}',
],
]
);
$this->add_control(
'options_btn_checkout',
[
'label' => __( 'Checkout', text_domain ),
'type' => Controls_Manager::HEADING,
'separator' => 'before',
]
);
$this->add_control(
'color_btn_checkout',
[
'label' => __( 'Color', text_domain ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .buttons .checkout' => 'color: {{VALUE}}',
],
]
);
$this->add_control(
'bg_color_btn_checkout',
[
'label' => __( 'Background Color', text_domain ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .buttons .checkout' => 'background-color: {{VALUE}}',
],
]
);
$this->end_controls_tab();
$this->start_controls_tab('style_btn_hover_tab', ['label' => __( 'Hover', text_domain ),]);
$this->add_control(
'cart_total_options_hover',
[
'label' => __( 'Cart Total ', text_domain ),
'type' => Controls_Manager::HEADING,
]
);
$this->add_control(
'color_cart_total_hover',
[
'label' => __( 'Color', text_domain ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .woocommerce-mini-cart__total:hover' => 'color: {{VALUE}}',
],
]
);
$this->add_control(
'bg_color_cart_total_hover',
[
'label' => __( 'Background Color', text_domain ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .woocommerce-mini-cart__total_hover' => 'background-color: {{VALUE}}',
],
]
);
$this->add_control(
'options_btn_forward_hover',
[
'label' => __( 'Wc Forward', text_domain ),
'type' => Controls_Manager::HEADING,
'separator' => 'before',
]
);
$this->add_control(
'color_btn_forward_hover',
[
'label' => __( 'Color', text_domain ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .buttons .wc-forward:hover' => 'color: {{VALUE}}',
],
]
);
$this->add_control(
'bg_color_btn_forward_hover',
[
'label' => __( 'Background Color', text_domain ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .buttons .wc-forward:hover' => 'background-color: {{VALUE}}',
],
]
);
$this->add_control(
'options_btn_checkout_hover',
[
'label' => __( 'Checkout', text_domain ),
'type' => Controls_Manager::HEADING,
'separator' => 'before',
]
);
$this->add_control(
'color_btn_checkout_hover',
[
'label' => __( 'Color', text_domain ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .buttons .checkout:hover' => 'color: {{VALUE}}',
],
]
);
$this->add_control(
'bg_color_btn_checkout_hover',
[
'label' => __( 'Background Color', text_domain ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .buttons .checkout:hover' => 'background-color: {{VALUE}}',
],
]
);
$this->end_controls_tab();
$this->end_controls_tabs();
$this->add_control(
'btn_basket_margin',
[
'label' => __( 'Margin', text_domain ),
'type' => Controls_Manager::DIMENSIONS,
'size_units' => [ 'px', '%', 'em' ],
'default' => [
'top' => '4',
'right' => '4',
'bottom' => '4',
'left' => '4',
'unit' => 'px',
],
'selectors' => [
'{{WRAPPER}} .buttons a, {{WRAPPER}} .woocommerce-mini-cart__total' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
],
]
);
$this->add_control(
'btn_basket_padding',
[
'label' => __( 'Padding', text_domain ),
'type' => Controls_Manager::DIMENSIONS,
'size_units' => [ 'px', '%', 'em' ],
'default' => [
'top' => '3',
'right' => '8',
'bottom' => '3',
'left' => '8',
'unit' => 'px',
],
'selectors' => [
'{{WRAPPER}} .buttons a, {{WRAPPER}} .woocommerce-mini-cart__total' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
],
]
);
$this->add_control(
'btn_basket_border_radius',
[
'label' => __( 'Border Radius', text_domain ),
'type' => Controls_Manager::DIMENSIONS,
'size_units' => [ 'px', '%', 'em' ],
'default' => [
'top' => '50',
'right' => '50',
'bottom' => '50',
'left' => '50',
'unit' => 'px',
],
'selectors' => [
'{{WRAPPER}} .buttons a, {{WRAPPER}} .woocommerce-mini-cart__total' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
],
]
);
$this->add_group_control(
Group_Control_Border::get_type(),
[
'name' => 'btn_basket_border',
'label' => __( 'Border', text_domain ),
'selector' => '{{WRAPPER}} .buttons a, {{WRAPPER}} .woocommerce-mini-cart__total',
]
);
$this->add_group_control(
Group_Control_Box_Shadow::get_type(),
[
'name' => 'btn_basket_box_shadow',
'label' => __( 'Box Shadow', text_domain ),
'selector' => '{{WRAPPER}} .buttons a, {{WRAPPER}} .woocommerce-mini-cart__total',
]
);
$this->end_controls_section();
}
protected function register_general_btn_style_controls() {
$this->start_controls_section(
'section_btn_style',
[
'label' => __( 'Button Style', text_domain ),
'tab' => Controls_Manager::TAB_STYLE,
]
);
$this->add_control(
'icon_space',
[
'label' => __( 'Icon Space', text_domain ),
'type' => Controls_Manager::SLIDER,
'size_units' => [ 'px' ],
'range' => [
'px' => [
'min' => 0,
'max' => 50,
'step' => 1,
],
],
'selectors' => [
'{{WRAPPER}} .drop-down-btn i' => 'margin: 0 {{SIZE}}{{UNIT}};',
],
]
);
$this->add_group_control(
Group_Control_Typography::get_type(),
[
'name' => 'btn_typography',
'label' => __( 'Typography', text_domain ),
'selector' => '{{WRAPPER}} .drop-down-btn',
]
);
$this->start_controls_tabs( 'tabs_button_colors' );
$this->start_controls_tab('tab_button_normal',['label' => __( 'Normal', text_domain ),]);
$this->add_control(
'btn_text_color',
[
'label' => __( 'Text Color', text_domain ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .drop-down-btn' => 'color: {{VALUE}}',
],
]
);
$this->add_control(
'btn_icon_color',
[
'label' => __( 'Icon Color', text_domain ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .drop-down-btn i' => 'color: {{VALUE}}',
],
]
);
$this->add_control(
'btn_bg',
[
'label' => __( 'Background Color', text_domain ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .drop-down-btn' => 'background-color: {{VALUE}}',
],
]
);
$this->add_group_control(
Group_Control_Border::get_type(),
[
'name' => 'btn_border',
'label' => __( 'Border', text_domain ),
'selector' => '{{WRAPPER}} .drop-down-btn',
]
);
$this->end_controls_tab();
$this->start_controls_tab('tab_button_hover',['label' => __( 'Hover', text_domain ),]);
$this->add_control(
'h_btn_text_color',
[
'label' => __( 'Text Color', text_domain ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .drop-down-btn:hover' => 'color: {{VALUE}}',
],
]
);
$this->add_control(
'h_btn_icon_color',
[
'label' => __( 'Icon Color', text_domain ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .drop-down-btn:hover i' => 'color: {{VALUE}}',
],
]
);
$this->add_control(
'h_btn_bg',
[
'label' => __( 'Background Color', text_domain ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .drop-down-btn:hover' => 'background-color: {{VALUE}}',
],
]
);
$this->add_group_control(
Group_Control_Border::get_type(),
[
'name' => 'btn_border_hover',
'label' => __( 'Border', text_domain ),
'selector' => '{{WRAPPER}} .drop-down-btn:hover',
]
);
$this->end_controls_tab();
$this->end_controls_tabs();
$this->add_control(
'btn_margin',
[
'label' => __( 'Margin', text_domain ),
'type' => Controls_Manager::DIMENSIONS,
'size_units' => [ 'px', '%', 'em' ],
'selectors' => [
'{{WRAPPER}} .drop-down-btn' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
],
]
);
$this->add_control(
'btn_padding',
[
'label' => __( 'Padding', text_domain ),
'type' => Controls_Manager::DIMENSIONS,
'size_units' => [ 'px', '%', 'em' ],
'selectors' => [
'{{WRAPPER}} .drop-down-btn' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
],
]
);
$this->add_control(
'btn_border_radius',
[
'label' => __( 'Border Radius', text_domain ),
'type' => Controls_Manager::DIMENSIONS,
'size_units' => [ 'px', '%', 'em' ],
'selectors' => [
'{{WRAPPER}} .drop-down-btn' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
],
]
);
$this->add_group_control(
Group_Control_Box_Shadow::get_type(),
[
'name' => 'btn_box_shadow',
'label' => __( 'Box Shadow', text_domain ),
'selector' => '{{WRAPPER}} .drop-down-btn',
]
);
$this->add_control(
'card_number_options',
[
'label' => __( 'Card Number Options', text_domain ),
'type' => Controls_Manager::HEADING,
'separator' => 'before',
]
);
$this->start_controls_tabs( 'tabs_button_colors_count' );
$this->start_controls_tab('tab_button_normal_count',['label' => __( 'Normal', text_domain ),]);
$this->add_control(
'card_number_color',
[
'label' => __( 'Icon Color', text_domain ),
'type' => Controls_Manager::COLOR,
'default' => '#FFF',
'selectors' => [
'{{WRAPPER}} .card-count' => 'color: {{VALUE}}',
],
]
);
$this->add_control(
'card_number_bg',
[
'label' => __( 'Background Color', text_domain ),
'type' => Controls_Manager::COLOR,
'default' => '#F00',
'selectors' => [
'{{WRAPPER}} .card-count' => 'background-color: {{VALUE}}',
],
]
);
$this->end_controls_tab();
$this->start_controls_tab('tab_button_hover_count',['label' => __( 'Hover', text_domain ),]);
$this->add_control(
'card_number_color_hover',
[
'label' => __( 'Icon Color', text_domain ),
'type' => Controls_Manager::COLOR,
'default' => '#FFF',
'selectors' => [
'{{WRAPPER}} .drop-down-btn:hover .card-count' => 'color: {{VALUE}}',
],
]
);
$this->add_control(
'card_number_bg_hover',
[
'label' => __( 'Background Color', text_domain ),
'type' => Controls_Manager::COLOR,
'default' => '#F00',
'selectors' => [
'{{WRAPPER}} .drop-down-btn:hover .card-count' => 'background-color: {{VALUE}}',
],
]
);
$this->end_controls_tab();
$this->end_controls_tabs();
$this->add_control(
'paddnig_count',
[
'label' => __( 'Padding', text_domain ),
'type' => Controls_Manager::DIMENSIONS,
'size_units' => [ 'px', '%', 'em' ],
'seperator' => 'before',
'default' => [
'top' => '8',
'right' => '8',
'bottom' => '7',
'left' => '8',
'unit' => 'px',
'isLinked' => false,
],
'selectors' => [
'{{WRAPPER}} .card-count' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
],
]
);
$this->add_control(
'card_count_position',
[
'label' => __( 'Card Count Position', text_domain ),
'type' => Controls_Manager::DIMENSIONS,
'size_units' => [ 'px', '%', 'em' ],
'allowed_dimensions' => [ 'top', 'right' ],
'default' => [
'top' => '-12',
'right' => '-12',
'unit' => 'px',
'isLinked' => false,
],
'selectors' => [
'{{WRAPPER}} .card-count' => 'top: {{TOP}}{{UNIT}};right: {{RIGHT}}{{UNIT}};',
],
]
);
$this->add_group_control(
Group_Control_Border::get_type(),
[
'name' => 'border_count',
'label' => __( 'Border', text_domain ),
'selector' => '{{WRAPPER}} .card-count',
]
);
$this->end_controls_section();
}
protected function render() {
$settings = $this->get_settings();
$show_count_cart = $settings['show_count_cart'];
$btn_text = $settings['btn_text'];
$btn_align = $settings['btn_align'];
$editor = Plugin::$instance->editor->is_edit_mode();
$this->add_render_attribute( 'btn_class','class', ['drop-down-btn', 'inline-flex', 'align-items-center'] );
if ($btn_align == 'left') {
$this->add_render_attribute( 'btn_class','class', ['flex-row-reverse', 'justify-content-end']);
}
$btn_class = $this->get_render_attribute_string( 'btn_class' );
$align = $settings['align'];
$aligns = '';
switch ($align) {
case 'left' :
$aligns = ' left-0';
break;
case 'center' :
$aligns = ' center-50';
break;
case 'right' :
$aligns = ' right-0';
break;
}
echo "<div class='shopping-cart drop-down flex justify-content-$align'>"
. "<div>"
. "<div $btn_class>$btn_text ";
Icons_Manager::render_icon( $settings['btn_icon'], [ 'aria-hidden' => 'true' ] );
if ($show_count_cart == 'yes') {
if (! $editor) {
$cart_count = WC()->cart->get_cart_contents_count();
if ($cart_count > 0) {echo "<span class='card-count'>$cart_count</span>";}
} else {
echo "<span class='card-count'>1</span>";
}
}
echo "</div>";
echo "<div class='drop-down-offcanvas shopping-cart-content drop-down-content$aligns'>"
. '<div class="widget_shopping_cart_content">';
if (! $editor) {
woocommerce_mini_cart();
}
echo '</div>'
. "</div>";
echo "</div>"
. "</div>";
}
}
Plugin::instance()->widgets_manager->register( new TMT_Basket );