fahimmurshed

class-free-gifts.php

Oct 20th, 2025
1,365
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.54 KB | None | 0 0
  1. <?php
  2. // Replcae the code to: /wp-content/themes/woodmart/inc/modules/layouts/elementor/woocommerce/class-free-gifts.php
  3. /**
  4.  * Manual free gifts table.
  5.  *
  6.  * @package Woodmart
  7.  */
  8.  
  9. namespace XTS\Modules\Layouts;
  10.  
  11. use Elementor\Group_Control_Typography;
  12. use Elementor\Controls_Manager;
  13. use Elementor\Plugin;
  14. use Elementor\Widget_Base;
  15. use XTS\Modules\Free_Gifts\Frontend as Free_Gifts_Frontend;
  16.  
  17. if ( ! defined( 'ABSPATH' ) ) {
  18.     exit; // Direct access not allowed.
  19. }
  20.  
  21. // Prevent fatal error: only declare if not already defined.
  22. if ( ! class_exists( 'XTS\\Modules\\Layouts\\Free_Gifts' ) ) {
  23.  
  24.     /**
  25.      * Elementor widget that inserts an embeddable content into the page, from any given URL.
  26.      */
  27.     class Free_Gifts extends Widget_Base {
  28.         /**
  29.          * Get widget name.
  30.          *
  31.          * @return string Widget name.
  32.          */
  33.         public function get_name() {
  34.             return 'wd_cart_free_gifts';
  35.         }
  36.  
  37.         /**
  38.          * Get widget title.
  39.          *
  40.          * @return string Widget title.
  41.          */
  42.         public function get_title() {
  43.             return esc_html__( 'Free gifts', 'woodmart' );
  44.         }
  45.  
  46.         /**
  47.          * Get widget icon.
  48.          *
  49.          * @return string Widget icon.
  50.          */
  51.         public function get_icon() {
  52.             return 'wd-icon-ct-free-gifts';
  53.         }
  54.  
  55.         /**
  56.          * Get widget categories.
  57.          *
  58.          * @return array Widget categories.
  59.          */
  60.         public function get_categories() {
  61.             return array( 'wd-site-elements' );
  62.         }
  63.  
  64.         /**
  65.          * Show in panel.
  66.          *
  67.          * @return bool Whether to show the widget in the panel or not.
  68.          */
  69.         public function show_in_panel() {
  70.             return Main::is_layout_type( 'cart' ) || Main::is_layout_type( 'checkout_form' );
  71.         }
  72.  
  73.         /**
  74.          * Register the widget controls.
  75.          */
  76.         protected function register_controls() {
  77.             /**
  78.              * Style tab.
  79.              */
  80.  
  81.             /**
  82.              * General settings.
  83.              */
  84.             $this->start_controls_section(
  85.                 'general_style_section',
  86.                 array(
  87.                     'label' => esc_html__( 'Title', 'woodmart' ),
  88.                     'tab'   => Controls_Manager::TAB_STYLE,
  89.                 )
  90.             );
  91.  
  92.             $this->add_control(
  93.                 'css_classes',
  94.                 array(
  95.                     'type'         => 'wd_css_class',
  96.                     'default'      => 'wd-cart-free-gifts',
  97.                     'prefix_class' => '',
  98.                 )
  99.             );
  100.  
  101.             $this->add_group_control(
  102.                 Group_Control_Typography::get_type(),
  103.                 array(
  104.                     'name'     => 'title_typography',
  105.                     'label'    => esc_html__( 'Typography', 'woodmart' ),
  106.                     'selector' => '{{WRAPPER}} .wd-el-title',
  107.                 )
  108.             );
  109.  
  110.             $this->add_control(
  111.                 'title_color',
  112.                 array(
  113.                     'label'     => esc_html__( 'Color', 'woodmart' ),
  114.                     'type'      => Controls_Manager::COLOR,
  115.                     'selectors' => array(
  116.                         '{{WRAPPER}} .wd-el-title' => 'color: {{VALUE}}',
  117.                     ),
  118.                 )
  119.             );
  120.  
  121.             $this->end_controls_section();
  122.         }
  123.  
  124.         /**
  125.          * Render the widget output on the frontend.
  126.          */
  127.         protected function render() {
  128.             if ( ! woodmart_get_opt( 'free_gifts_enabled', 0 ) || ! is_object( WC()->cart ) || 0 === WC()->cart->get_cart_contents_count() ) {
  129.                 return;
  130.             }
  131.  
  132.             $free_gifts_frontend = Free_Gifts_Frontend::get_instance();
  133.  
  134.             ob_start();
  135.  
  136.             $free_gifts_frontend->render_free_gifts_table();
  137.  
  138.             $gifts_table  = ob_get_clean();
  139.             $is_edit_mode = woodmart_elementor_is_edit_mode() || woodmart_elementor_is_preview_page() || woodmart_elementor_is_preview_mode();
  140.  
  141.             woodmart_enqueue_js_script( 'free-gifts-table' );
  142.  
  143.             if ( $gifts_table || ! $is_edit_mode ) {
  144.                 echo '<div class="wd-fg">' . $gifts_table . '</div>';
  145.             }
  146.         }
  147.     }
  148.  
  149.     // Register the widget only once.
  150.     Plugin::instance()->widgets_manager->register( new Free_Gifts() );
  151.  
  152. } // End if class_exists check.
  153.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment