Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions assets/css/admin/facebook-for-woocommerce-whatsapp-banner.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
.fb-wa-banner {
display: block;
position: relative;
box-sizing: border-box;
width: 1000px;
margin-bottom: 20px;
padding: 16px;
color: #050505;
background: #fff;
box-shadow: 0 0 3px rgba(0, 0, 0, 0.2);
}

.fb-wa-banner p,
.fb-wa-banner h2 {
font-family: Helvetica, Arial, sans-serif;
font-size: 20px;
line-height: 24px;
color:#606770;
}

.fb-wa-banner h2 {
font-weight: 600;
color: #1c1e21;
}

.fb-wa-banner .wa-cta-button {
display: inline-block;
cursor: pointer;
border: 1px solid;
width: 151px;
border-radius: 6px;
text-decoration: none;
box-sizing: content-box;
font-size: 16px;
line-height: 34px;
-webkit-font-smoothing: antialiased;
font-weight: bold;
justify-content: center;
padding: 0 8px;
position: relative;
text-align: center;
text-shadow: none;
vertical-align: middle;
transition: 200ms cubic-bezier(.08, .52, .52, 1) background-color, 200ms cubic-bezier(.08, .52, .52, 1) box-shadow, 200ms cubic-bezier(.08, .52, .52, 1) transform;
padding: 0 16px;
color: #fff;
background-color: #1877f2;
border-color: #1877f2;
}

.fb-wa-banner .wa-cta-button:hover {
background-color: #1763cf;
border-color: #1763cf;
}

.fb-wa-banner .wa-close-button {
position: absolute;
display: block;
width: 16px;
height: 16px;
padding: 5px;
right: 16px;
top: 16px;
}
1 change: 1 addition & 0 deletions assets/images/ico-close.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/ico-whatsapp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions assets/js/admin/whatsapp-admin-banner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
jQuery(function ($) {
$(document).on('click', '.fb-wa-banner .wa-close-button', function (e) {
e.preventDefault();

$.post(WCFBAdminBanner.ajax_url, {
action: 'wc_facebook_dismiss_banner',
nonce: WCFBAdminBanner.nonce,
banner_id: WCFBAdminBanner.banner_id
}).done(function (response) {
$('.fb-wa-banner').remove();
});
});
});
128 changes: 128 additions & 0 deletions facebook-commerce-admin-banner.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?php
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
*
* This source code is licensed under the license found in the
* LICENSE file in the root directory of this source tree.
*
* @package FacebookCommerce
*/

/**
* Outputs WhatApp utility messaging recruitment admin banner
*
* @since x.x.x
*/

/**
* WhatsApp Admin Banner class for Facebook for WooCommerce.
*/
class WC_Facebookcommerce_Admin_Banner {
const BANNER_ID = 'wc_facebook_admin_banner';

public function __construct() {
add_action(
'admin_enqueue_scripts',
array( $this, 'enqueue_banner_script' )
);
add_action(
'wp_ajax_wc_facebook_dismiss_banner',
array( $this, 'ajax_dismiss_banner' )
);
}

/**
* Enqueue the admin banner script and localize data.
*/
public function enqueue_banner_script() {
wp_enqueue_script(
'whatsapp-admin-banner',
plugins_url(
'assets/js/admin/whatsapp-admin-banner.js',
__FILE__
),
array( 'jquery' ),
'1.0',
true
);
wp_localize_script(
'whatsapp-admin-banner',
'WCFBAdminBanner',
array(
'ajax_url' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( self::BANNER_ID ),
'banner_id' => self::BANNER_ID,
)
);
}

/**
* AJAX handler to dismiss the banner.
*/
public function ajax_dismiss_banner() {
check_ajax_referer( self::BANNER_ID, 'nonce' );
update_user_meta(
get_current_user_id(),
self::BANNER_ID,
1
);
}

/**
* Output the banner HTML if it should be shown.
*/
public function render_banner() {
// Check if the WhatsApp admin banner should be shown.
if ( strtotime( 'now' ) > strtotime( '2025-06-15 23:59:59' ) ) {
return;
}

if ( ! current_user_can( 'manage_woocommerce' ) ) {
return;
}

if ( get_user_meta(
get_current_user_id(),
self::BANNER_ID,
true
) ) {
return;
}

$banner_html = '<div class="fb-wa-banner" data-nonce="' .
esc_attr( wp_create_nonce( self::BANNER_ID ) ) .
'" data-banner-id="' .
esc_attr( self::BANNER_ID ) .
'">';
$banner_html .= '<img src="' .
esc_url(
plugins_url(
'assets/images/ico-whatsapp.png',
__FILE__
)
) .
'" width="36" height="36" alt="WhatsApp Logo" />';
$banner_html .= '<h2>Sign up to test WhatsApp’s new integration with '
. 'WooCommerce</h2>';
$banner_html .= '<p>We’re launching a brand new WhatsApp integration for '
. 'WooCommerce allowing businesses to send order tracking notifications '
. 'on WhatsApp. Sign up for a chance to join our testing program and get '
. 'early access to this new feature. As a thank you, participants who '
. 'complete testing will receive a $500 ad credit.</p>';
$banner_html .= '<a class="wa-cta-button" '
. 'href="https://facebookpso.qualtrics.com/jfe/form/SV_0SVseus9UADOhhQ"'
. '>Sign Up</a>';
$banner_html .= '<a class="wa-close-button" title="Close banner" '
. 'href="#"><img src="' .
esc_url(
plugins_url(
'assets/images/ico-close.svg',
__FILE__
)
) .
'" width="16" height="16" alt="Close button" /></a>';
$banner_html .= '</div>';

echo wp_kses_post( $banner_html );
}
}
14 changes: 14 additions & 0 deletions facebook-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ function () {
}
}
);

if ( is_admin() ) {
add_action(
'admin_init',
function () {
if ( ! class_exists( 'WC_Facebookcommerce_Admin_Banner' ) ) {
require_once plugin_dir_path( __FILE__ ) .
'facebook-commerce-admin-banner.php';
}
new WC_Facebookcommerce_Admin_Banner();
}
);
}

/**
* The plugin loader class.
*
Expand Down
5 changes: 5 additions & 0 deletions includes/Admin/Settings_Screens/Advertise.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public function enqueue_assets() {
return;
}
wp_enqueue_style( 'wc-facebook-admin-advertise-settings', facebook_for_woocommerce()->get_plugin_url() . '/assets/css/admin/facebook-for-woocommerce-advertise.css', array(), \WC_Facebookcommerce::VERSION );
wp_enqueue_style( 'wc-facebook-admin-whatsapp-banner', facebook_for_woocommerce()->get_plugin_url() . '/assets/css/admin/facebook-for-woocommerce-whatsapp-banner.css', array(), \WC_Facebookcommerce::VERSION );
}


Expand Down Expand Up @@ -209,7 +210,11 @@ public function render() {

$fbe_extras = wp_json_encode( $this->get_lwi_ads_configuration_data() );

$wa_banner = new \WC_Facebookcommerce_Admin_Banner();
$wa_banner->render_banner();
$wa_banner->enqueue_banner_script();
?>

<script async defer src="<?php echo esc_url( $this->get_lwi_ads_sdk_url() ); ?>"></script>
<div
class="fb-lwi-ads-creation"
Expand Down