Skip to content

Commit 9a16825

Browse files
committed
Add happy addons banner
1 parent 8d2d09f commit 9a16825

5 files changed

Lines changed: 158 additions & 0 deletions

File tree

assets/css/style.css

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,3 +326,56 @@ PLEASE DO NOT MODIFY*/
326326
visibility: visible;
327327
opacity: 1;
328328
}
329+
.wcct-notice-wrap {
330+
overflow: hidden;
331+
padding: 22px 15px;
332+
}
333+
.wcct-message-icon {
334+
width: 10%;
335+
float: left;
336+
}
337+
.wcct-message-icon img {
338+
height: 50px;
339+
}
340+
.wcct-message-content {
341+
width: 70%;
342+
float: left;
343+
margin-top: 20px;
344+
}
345+
.wcct-message-content p {
346+
font-size: 16px;
347+
padding: 0;
348+
margin: 0;
349+
}
350+
.wcct-message-action {
351+
width: 16.5%;
352+
float: right;
353+
text-align: center;
354+
margin-right: 1.2%;
355+
}
356+
#wcct_remote_notice {
357+
display: none;
358+
}
359+
#wcct-install-happ-addons {
360+
background: #5c41d2 !important;
361+
border-color: #5c41d2 !important;
362+
box-shadow: 0 1px 0 #5c41d2;
363+
color: #fff;
364+
text-decoration: none;
365+
text-shadow: 0 -1px 1px #5c41d2, 1px 0 1px #5c41d2, 0 1px 1px #5c41d2, -1px 0 1px #5c41d2;
366+
height: inherit;
367+
padding: 4px 20px;
368+
display: flex;
369+
align-items: center;
370+
}
371+
#wcct-install-happ-addons i {
372+
margin-right: 7px;
373+
}
374+
#wcct-install-happ-addons:hover {
375+
background: #150654 !important;
376+
border-color: #150654 !important;
377+
box-shadow: 0 1px 0 #150654;
378+
color: #fff;
379+
text-decoration: none;
380+
text-shadow: 0 -1px 1px #150654, 1px 0 1px #150654, 0 1px 1px #150654, -1px 0 1px #150654;
381+
}

assets/images/happy-addons.png

9.77 KB
Loading

assets/js/admin.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,27 @@
8888
$( tooltipText ).text( newText );
8989
} );
9090

91+
// Install and activate happy addons
92+
$( '#wcct-install-happ-addons' ).on( 'click', function( e ) {
93+
e.preventDefault();
94+
var loader = $( '#wcct-preloader' );
95+
$('.wcct-update-icon').remove();
96+
$(this).text('Installing...');
97+
$(this).addClass( 'updating-message' );
98+
loader.show();
99+
var remote_message = $( '#wcct_remote_notice' );
100+
wp.ajax.send( 'activate_happy_addons', {
101+
success: function( response ) {
102+
$('.wcct-notice-wrap').hide();
103+
loader.hide();
104+
remote_message.show();
105+
remote_message.html('<p><strong>' + response.message + 'Happy Addons !</strong></p>');
106+
},
107+
error: function( error ) {
108+
loader.hide();
109+
remote_message.html('<p><strong>' + response.message + '</strong></p>');
110+
}
111+
} );
112+
} );
113+
91114
})( jQuery );

conversion-tracking.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ public function init_hooks() {
181181
add_action( 'init', array( $this, 'init_tracker' ) );
182182
add_action( 'admin_notices', array( $this, 'check_woocommerce_exist' ) );
183183
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) );
184+
add_action( 'admin_notices', array( $this, 'happy_addons_ads_banner' ) );
184185
}
185186

186187
/**
@@ -286,6 +287,40 @@ public function check_woocommerce_exist() {
286287
<?php
287288
}
288289
}
290+
291+
/**
292+
* Add happy addons ads banner
293+
*
294+
* @return void
295+
*/
296+
public function happy_addons_ads_banner() {
297+
if ( ! class_exists( '\Elementor\Plugin' ) ) {
298+
return;
299+
}
300+
301+
if ( class_exists( '\Happy_Addons\Elementor\Base' ) ) {
302+
return;
303+
}
304+
305+
?>
306+
<div id="wcct_remote_notice" class="notice notice-success">
307+
</div>
308+
<div class="notice wcct-notice-wrap">
309+
<div class="wcct-message-icon">
310+
<img src="<?php echo WCCT_ASSETS . '/images/happy-addons.png'?>" alt="">
311+
</div>
312+
<div class="wcct-message-content">
313+
<p><?php _e( 'Reach beyond your imagination in creating web pages. <strong> Try Happy Addons for Elementor to shape your dream.</strong> 😊') ?></p>
314+
</div>
315+
<div class="wcct-message-action">
316+
<a href="" id="wcct-install-happ-addons" class="button button-primary"> <i class="dashicons dashicons-update wcct-update-icon"></i> Install Now For FREE</a>
317+
<p></strong><a target="_blank" href="https://wordpress.org/plugins/happy-elementor-addons/">Read more details ➔</a>
318+
</p>
319+
</div>
320+
</div>
321+
322+
<?php
323+
}
289324
}
290325

291326
function wcct_init() {

includes/class-ajax.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class WCCT_Ajax {
1010
*/
1111
public function __construct() {
1212
add_action( 'wp_ajax_wcct_save_settings', array( $this, 'wcct_save_settings' ) );
13+
add_action( 'wp_ajax_activate_happy_addons', array( $this, 'wcct_install_happy_addons' ) );
1314
}
1415

1516
/**
@@ -42,4 +43,50 @@ public function wcct_save_settings() {
4243
) );
4344

4445
}
46+
/**
47+
* Install the Happy addons via ajax
48+
*
49+
* @return json
50+
*/
51+
public function wcct_install_happy_addons() {
52+
53+
include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
54+
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
55+
56+
$upgrader = new Plugin_Upgrader( new WP_Ajax_Upgrader_Skin() );
57+
58+
$plugin = 'happy-elementor-addons';
59+
$api = plugins_api( 'plugin_information', array( 'slug' => $plugin, 'fields' => array( 'sections' => false ) ) );
60+
61+
62+
if (is_wp_error($api)) {
63+
die(sprintf(__('ERROR: Error fetching plugin information: %s', 'woocommerce-conversion-tracking'), $api->get_error_message()));
64+
}
65+
66+
add_filter( 'upgrader_package_options', function ( $options ) {
67+
$options['clear_destination'] = true;
68+
$options['hook_extra'] = [
69+
'type' => 'plugin',
70+
'action' => 'install',
71+
'plugin' => 'happy-elementor-addons/plugin.php',
72+
];
73+
return $options;
74+
});
75+
76+
$result = $upgrader->install( $api->download_link );
77+
78+
if ( is_wp_error( $result ) ) {
79+
wp_send_json_error( $result );
80+
}
81+
82+
$result = activate_plugin( 'happy-elementor-addons/plugin.php' );
83+
84+
if ( is_wp_error( $result ) ) {
85+
wp_send_json_error( $result );
86+
}
87+
wp_send_json_success([
88+
'message' => __( 'Successfully installed and activate,', 'woocommerce-conversion-tracking' )
89+
]);
90+
}
91+
4592
}

0 commit comments

Comments
 (0)