| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Elementor Deal Block |
| 5 |
* |
| 6 |
* @package Copy the Code |
| 7 |
* @since 3.1.0 |
| 8 |
*/ |
| 9 |
namespace CopyTheCode\Elementor\Block; |
| 10 |
|
| 11 |
use CopyTheCode\Helpers; |
| 12 |
use Elementor\Utils; |
| 13 |
use Elementor\Widget_Base; |
| 14 |
use Elementor\Controls_Manager; |
| 15 |
/** |
| 16 |
* Deal Block |
| 17 |
* |
| 18 |
* @since 3.1.0 |
| 19 |
*/ |
| 20 |
class Deal extends Widget_Base { |
| 21 |
/** |
| 22 |
* Constructor |
| 23 |
* |
| 24 |
* @param array $data |
| 25 |
* @param array $args |
| 26 |
* |
| 27 |
* @since 3.1.0 |
| 28 |
*/ |
| 29 |
public function __construct( $data = [], $args = null ) { |
| 30 |
parent::__construct( $data, $args ); |
| 31 |
// Block. |
| 32 |
wp_enqueue_style( |
| 33 |
'ctc-el-deal', |
| 34 |
COPY_THE_CODE_URI . 'classes/elementor/widgets/deal/style.css', |
| 35 |
[], |
| 36 |
COPY_THE_CODE_VER, |
| 37 |
'all' |
| 38 |
); |
| 39 |
wp_enqueue_script( |
| 40 |
'ctc-el-deal', |
| 41 |
COPY_THE_CODE_URI . 'classes/elementor/widgets/deal/script.js', |
| 42 |
[], |
| 43 |
COPY_THE_CODE_VER, |
| 44 |
true |
| 45 |
); |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Get style dependencies |
| 50 |
*/ |
| 51 |
public function get_style_depends() { |
| 52 |
return ['ctc-el-deal']; |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Get script dependencies |
| 57 |
*/ |
| 58 |
public function get_script_depends() { |
| 59 |
return ['ctc-el-deal']; |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* Get name |
| 64 |
*/ |
| 65 |
public function get_name() { |
| 66 |
return 'ctc_deal'; |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* Get title |
| 71 |
*/ |
| 72 |
public function get_title() { |
| 73 |
return esc_html__( 'Deal', 'copy-the-code' ); |
| 74 |
} |
| 75 |
|
| 76 |
/** |
| 77 |
* Get icon |
| 78 |
*/ |
| 79 |
public function get_icon() { |
| 80 |
return 'eicon-basket-solid'; |
| 81 |
} |
| 82 |
|
| 83 |
/** |
| 84 |
* Get categories |
| 85 |
*/ |
| 86 |
public function get_categories() { |
| 87 |
return Helpers::get_categories(); |
| 88 |
} |
| 89 |
|
| 90 |
/** |
| 91 |
* Get keywords |
| 92 |
*/ |
| 93 |
public function get_keywords() { |
| 94 |
return Helpers::get_keywords( [ |
| 95 |
'deal', |
| 96 |
'offer', |
| 97 |
'coupon', |
| 98 |
'sale' |
| 99 |
] ); |
| 100 |
} |
| 101 |
|
| 102 |
/** |
| 103 |
* Render |
| 104 |
*/ |
| 105 |
public function render() { |
| 106 |
$image = $this->get_settings_for_display( 'image' ); |
| 107 |
$heading = $this->get_settings_for_display( 'heading' ); |
| 108 |
$description = $this->get_settings_for_display( 'description' ); |
| 109 |
$button_text = $this->get_settings_for_display( 'button_text' ); |
| 110 |
$button_link = $this->get_settings_for_display( 'button_link' ); |
| 111 |
$link_target = $this->get_settings_for_display( 'link_target' ); |
| 112 |
$details = $this->get_settings_for_display( 'details' ); |
| 113 |
$toggle_details = $this->get_settings_for_display( 'toggle_details' ); |
| 114 |
?> |
| 115 |
<div class="ctc-block ctc-deal"> |
| 116 |
<div class="ctc-deal-header"> |
| 117 |
<?php |
| 118 |
if ( $image['url'] ) { |
| 119 |
?> |
| 120 |
<div class="ctc-deal-image"> |
| 121 |
<img src="<?php |
| 122 |
echo esc_url( $image['url'] ); |
| 123 |
?>" alt="<?php |
| 124 |
echo esc_attr( $heading ); |
| 125 |
?>"> |
| 126 |
</div> |
| 127 |
<?php |
| 128 |
} |
| 129 |
?> |
| 130 |
<div class="ctc-deal-headings"> |
| 131 |
<h3 class="ctc-deal-heading"><?php |
| 132 |
echo esc_html( $heading ); |
| 133 |
?></h3> |
| 134 |
|
| 135 |
<?php |
| 136 |
if ( $description ) { |
| 137 |
?> |
| 138 |
<div class="ctc-deal-description"><?php |
| 139 |
echo wp_kses_post( wpautop( $description ) ); |
| 140 |
?></div> |
| 141 |
<?php |
| 142 |
} |
| 143 |
?> |
| 144 |
|
| 145 |
</div> |
| 146 |
<div class="ctc-deal-cta"> |
| 147 |
<a href="<?php |
| 148 |
echo esc_url( $button_link['url'] ); |
| 149 |
?>" target="<?php |
| 150 |
echo esc_attr( $link_target ); |
| 151 |
?>" class="ctc-deal-link"><?php |
| 152 |
echo esc_html( $button_text ); |
| 153 |
?></a> |
| 154 |
</div> |
| 155 |
</div> |
| 156 |
<?php |
| 157 |
if ( $details ) { |
| 158 |
?> |
| 159 |
<div class="ctc-deal-details"> |
| 160 |
<?php |
| 161 |
$toggle_details_class = ( 'yes' === $toggle_details ? 'ctc-toggle-details' : '' ); |
| 162 |
if ( 'yes' === $toggle_details ) { |
| 163 |
echo '<a href="#" class="ctc-deal-toggle-link">Show Details</a>'; |
| 164 |
} |
| 165 |
echo '<div class="ctc-details-content ' . $toggle_details_class . '">' . wp_kses_post( wpautop( $details ) ) . '</div>'; |
| 166 |
?> |
| 167 |
</div> |
| 168 |
<?php |
| 169 |
} |
| 170 |
?> |
| 171 |
</div> |
| 172 |
<?php |
| 173 |
} |
| 174 |
|
| 175 |
/** |
| 176 |
* Register controls |
| 177 |
*/ |
| 178 |
protected function _register_controls() { |
| 179 |
$this->start_controls_section( 'image_section', [ |
| 180 |
'label' => esc_html__( 'Deal Image', 'copy-the-code' ), |
| 181 |
] ); |
| 182 |
$this->add_control( 'image', [ |
| 183 |
'label' => esc_html__( 'Deal Image', 'copy-the-code' ), |
| 184 |
'type' => Controls_Manager::MEDIA, |
| 185 |
'default' => [ |
| 186 |
'url' => Utils::get_placeholder_image_src(), |
| 187 |
], |
| 188 |
] ); |
| 189 |
$this->end_controls_section(); |
| 190 |
$this->start_controls_section( 'heading_section', [ |
| 191 |
'label' => esc_html__( 'Heading', 'copy-the-code' ), |
| 192 |
] ); |
| 193 |
$this->add_control( 'heading', [ |
| 194 |
'label' => esc_html__( 'Heading', 'copy-the-code' ), |
| 195 |
'type' => Controls_Manager::TEXT, |
| 196 |
'default' => esc_html__( 'Get up to 10% off on all products', 'copy-the-code' ), |
| 197 |
] ); |
| 198 |
$this->end_controls_section(); |
| 199 |
$this->start_controls_section( 'description_section', [ |
| 200 |
'label' => esc_html__( 'Short Description', 'copy-the-code' ), |
| 201 |
] ); |
| 202 |
$this->add_control( 'description', [ |
| 203 |
'label' => esc_html__( 'Short Description', 'copy-the-code' ), |
| 204 |
'type' => Controls_Manager::WYSIWYG, |
| 205 |
'default' => 'Get up to 50% off on all products. Offer valid till <b>31st December 2020</b>.', |
| 206 |
] ); |
| 207 |
$this->end_controls_section(); |
| 208 |
$this->start_controls_section( 'button_section', [ |
| 209 |
'label' => esc_html__( 'Button', 'copy-the-code' ), |
| 210 |
] ); |
| 211 |
// Button Text. |
| 212 |
$this->add_control( 'button_text', [ |
| 213 |
'label' => esc_html__( 'Button Text', 'copy-the-code' ), |
| 214 |
'type' => Controls_Manager::TEXT, |
| 215 |
'default' => esc_html__( 'Get Deal', 'copy-the-code' ), |
| 216 |
] ); |
| 217 |
// Button Link. |
| 218 |
$this->add_control( 'button_link', [ |
| 219 |
'label' => esc_html__( 'Button Link', 'copy-the-code' ), |
| 220 |
'type' => Controls_Manager::URL, |
| 221 |
'default' => [ |
| 222 |
'url' => '#', |
| 223 |
], |
| 224 |
] ); |
| 225 |
// Link target. |
| 226 |
$this->add_control( 'link_target', [ |
| 227 |
'label' => esc_html__( 'Link Target', 'copy-the-code' ), |
| 228 |
'type' => Controls_Manager::SELECT, |
| 229 |
'default' => '_blank', |
| 230 |
'options' => [ |
| 231 |
'_self' => esc_html__( 'Self', 'copy-the-code' ), |
| 232 |
'_blank' => esc_html__( 'Blank', 'copy-the-code' ), |
| 233 |
], |
| 234 |
] ); |
| 235 |
$this->end_controls_section(); |
| 236 |
$this->start_controls_section( 'details_section', [ |
| 237 |
'label' => esc_html__( 'Details', 'copy-the-code' ), |
| 238 |
] ); |
| 239 |
// Details. |
| 240 |
$this->add_control( 'details', [ |
| 241 |
'label' => esc_html__( 'Details', 'copy-the-code' ), |
| 242 |
'type' => Controls_Manager::WYSIWYG, |
| 243 |
'default' => '<ul><li>Get upto 50% off on all products.</li><li> |
| 244 |
Offer valid till <b>31st December 2020</b>.</li><li>No coupon code required.</li></ul>', |
| 245 |
] ); |
| 246 |
// Enable Toggle Details. |
| 247 |
$this->add_control( 'toggle_details', [ |
| 248 |
'label' => esc_html__( 'Enable Toggle Details', 'copy-the-code' ), |
| 249 |
'type' => Controls_Manager::SWITCHER, |
| 250 |
'default' => 'yes', |
| 251 |
] ); |
| 252 |
$this->end_controls_section(); |
| 253 |
Helpers::register_pro_sections( $this, [ |
| 254 |
'Header', |
| 255 |
'Heading', |
| 256 |
'Description', |
| 257 |
'Button', |
| 258 |
'Details', |
| 259 |
'Details > Link', |
| 260 |
'Details > Content' |
| 261 |
] ); |
| 262 |
} |
| 263 |
|
| 264 |
} |
| 265 |
|