Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit 3a69b64

Browse files
authored
Upgrade to PayPal Payments Notice on Plugins Page (#866)
* Defined action & callback to show migration notice * Adds CSS/JS & template for notice * Use wp-plugin-delete-success event response to identify the plugin deleted and make changes accordingly * Disable notice if PayPal Payments is active * Add fix to handle plugin folder renames * Hide notice buttons by default & show via JS
1 parent 8696f2f commit 3a69b64

File tree

4 files changed

+172
-0
lines changed

4 files changed

+172
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
.plugins tr[data-slug=woocommerce-gateway-paypal-express-checkout] th, .plugins tr[data-slug=woocommerce-gateway-paypal-express-checkout] td {
2+
box-shadow: none !important;
3+
}
4+
5+
#ppec-migrate-notice .notice {
6+
padding: 1px 0 20px 0;
7+
}
8+
#ppec-migrate-notice .ppec-notice-section {
9+
padding: 0 20px;
10+
}
11+
#ppec-migrate-notice .ppec-notice-title {
12+
border-bottom: 1px solid #FFB900;
13+
}
14+
#ppec-migrate-notice .ppec-notice-title p {
15+
line-height: 30px;
16+
}
17+
#ppec-migrate-notice .ppec-notice-title p:before {
18+
vertical-align: middle;
19+
}
20+
#ppec-migrate-notice .ppec-notice-content p:first-of-type {
21+
margin-top: 20px;
22+
}
23+
#ppec-migrate-notice .ppec-notice-content p:before {
24+
display: none;
25+
}
26+
#ppec-migrate-notice .ppec-notice-content ul {
27+
list-style-type: disc;
28+
margin-left: 30px;
29+
}
30+
#ppec-migrate-notice .ppec-notice-buttons a {
31+
text-decoration: none;
32+
line-height: 34px;
33+
margin-right: 16px;
34+
}
35+
#ppec-migrate-notice .ppec-notice-buttons a:last-of-type {
36+
margin-right: 0;
37+
}
38+
#ppec-migrate-notice .ppec-notice-buttons a:before {
39+
vertical-align: middle;
40+
margin: -2.5px 5px 0 0;
41+
}
42+
#ppec-migrate-notice .ppec-notice-buttons a.updating-message:before {
43+
-webkit-animation: rotation 2s infinite linear;
44+
animation: rotation 2s infinite linear;
45+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
;(function ( $, window, document ) {
2+
'use strict';
3+
4+
// Check whether PayPal Payments is installed.
5+
let is_paypal_payments_installed = false,
6+
is_paypal_payments_active = false;
7+
8+
const targetElement = $( 'tr[data-slug="woocommerce-paypal-payments"]' );
9+
if ( targetElement.length ) {
10+
is_paypal_payments_installed = true;
11+
12+
if ( targetElement.hasClass( 'active' ) ) {
13+
is_paypal_payments_active = true;
14+
}
15+
16+
// Dynamically update plugin activation link to handle plugin folder renames.
17+
let activation_url = $( targetElement ).find( 'span.activate a' ).attr( 'href' );
18+
$( 'a#ppec-activate-paypal-payments' ).attr( 'href', activation_url );
19+
}
20+
21+
// Hide notice/buttons conditionally.
22+
if ( is_paypal_payments_installed && is_paypal_payments_active ) {
23+
$( 'tr#ppec-migrate-notice' ).hide();
24+
} else if ( is_paypal_payments_installed ) {
25+
$( 'a#ppec-install-paypal-payments' ).hide();
26+
} else {
27+
$( 'a#ppec-activate-paypal-payments' ).hide();
28+
}
29+
30+
// Display buttons area
31+
$( '#ppec-migrate-notice .ppec-notice-buttons' ).removeClass( 'hidden' );
32+
33+
// Handle delete event for PayPal Payments.
34+
$( document ).on( 'wp-plugin-delete-success', function( event, response ) {
35+
if ( is_paypal_payments_installed && 'woocommerce-paypal-payments' === response.slug ) {
36+
$( 'a#ppec-activate-paypal-payments' ).hide();
37+
$( 'a#ppec-install-paypal-payments' ).show();
38+
}
39+
} );
40+
41+
// Change button text when install link is clicked.
42+
$( document ).on( 'click', '#ppec-install-paypal-payments', function( e ) {
43+
e.preventDefault();
44+
$( this ).addClass( 'updating-message' ).text( 'Installing...' );
45+
const install_link = $( this ).attr('href');
46+
setTimeout( function(){
47+
window.location = install_link;
48+
}, 100 );
49+
});
50+
})( jQuery, window, document );

includes/class-wc-gateway-ppec-plugin.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ public function maybe_run() {
169169
add_filter( 'plugin_action_links_' . plugin_basename( $this->file ), array( $this, 'plugin_action_links' ) );
170170
add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 2 );
171171
add_action( 'wp_ajax_ppec_dismiss_notice_message', array( $this, 'ajax_dismiss_notice' ) );
172+
173+
add_action( 'after_plugin_row_' . plugin_basename( $this->file ), array( $this, 'ppec_upgrade_notice' ), 10, 3 );
172174
}
173175

174176
public function bootstrap() {
@@ -496,6 +498,22 @@ public static function needs_shipping() {
496498
return apply_filters( 'woocommerce_cart_needs_shipping', $needs_shipping );
497499
}
498500

501+
/**
502+
* Displays notice to upgrade to PayPal Payments.
503+
*
504+
* @param string $plugin_file Path to the plugin file relative to the plugins directory.
505+
* @param array $plugin_data An array of plugin data.
506+
* @param string $status Status filter currently applied to the plugin list.
507+
*/
508+
public function ppec_upgrade_notice( $plugin_file, $plugin_data, $status ) {
509+
// Load styles & scripts required for the notice.
510+
wp_enqueue_style( 'ppec-upgrade-notice', plugin_dir_url( __DIR__ ) . '/assets/css/admin/ppec-upgrade-notice.css', array(), WC_GATEWAY_PPEC_VERSION );
511+
wp_enqueue_script( 'ppec-upgrade-notice-js', plugin_dir_url( __DIR__ ) . '/assets/js/admin/ppec-upgrade-notice.js', array(), WC_GATEWAY_PPEC_VERSION, false );
512+
513+
// Load notice template.
514+
include_once $this->plugin_path . 'templates/paypal-payments-upgrade-notice.php';
515+
}
516+
499517
/* Deprecated Functions */
500518

501519
/**
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
/**
3+
* Show PayPal Payments upgrade notice on plugins page
4+
*
5+
* @package woocommerce-paypal-express-checkout/templates
6+
*/
7+
8+
9+
// Generate Install / Activation / Config links.
10+
$paypal_payments_path = 'woocommerce-paypal-payments/woocommerce-paypal-payments.php';
11+
$paypal_payments_install_link = wp_nonce_url(
12+
add_query_arg(
13+
array(
14+
'action' => 'install-plugin',
15+
'plugin' => dirname( $paypal_payments_path ),
16+
),
17+
admin_url( 'update.php' )
18+
),
19+
'install-plugin_' . dirname( $paypal_payments_path )
20+
);
21+
22+
$paypal_payments_activate_link = wp_nonce_url(
23+
add_query_arg(
24+
array(
25+
'action' => 'activate',
26+
'plugin' => $paypal_payments_path,
27+
),
28+
admin_url( 'plugins.php' )
29+
),
30+
'activate-plugin_' . $paypal_payments_path
31+
);
32+
?>
33+
34+
<tr class="plugin-update-tr active notice-warning notice-alt" id="ppec-migrate-notice">
35+
<td colspan="4" class="plugin-update colspanchange">
36+
<div class="update-message notice inline notice-warning notice-alt">
37+
<div class='ppec-notice-title ppec-notice-section'>
38+
<p>Upgrade to PayPal Payments: the best way to get paid with PayPal and WooCommerce</p>
39+
</div>
40+
<div class='ppec-notice-content ppec-notice-section'>
41+
<p><strong>WooCommerce PayPal Payments</strong> is a full-stack solution that offers powerful and flexible payment processing capabilities. Expand your business by connecting with over 370+ million active PayPal accounts around the globe. With PayPal, you can sell in 200+ markets and accept 100+ currencies. Plus, PayPal can automatically identify customer locations and offer country-specific, local payment methods.</p>
42+
43+
<p>Upgrade now and get access to these great features:</p>
44+
45+
<ul>
46+
<li>Give your customers their preferred ways to pay with one checkout solution. Accept <strong>PayPal</strong>, <strong>PayPal Credit</strong>, <strong>Pay Later</strong> options (available in the US, UK, France, and Germany), <strong>credit & debit cards</strong>, and country-specific, <strong>local payment methods</strong> on any device.</li>
47+
<li>Offer subscriptions and accept recurring payments as PayPal is compatible with <a target="_blank" href="https://woocommerce.com/products/woocommerce-subscriptions/"><strong>WooCommerce Subscriptions</strong></a>.</li>
48+
</ul>
49+
</div>
50+
<div class='ppec-notice-buttons ppec-notice-section hidden'>
51+
<?php //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
52+
<a id="ppec-install-paypal-payments" href="<?php echo $paypal_payments_install_link; ?>" class="button button-primary woocommerce-save-button">Upgrade to PayPal Payments now</a>
53+
<?php //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
54+
<a id="ppec-activate-paypal-payments" href="<?php echo $paypal_payments_activate_link; ?>" class="button button-primary woocommerce-save-button">Activate PayPal Payments now</a>
55+
<a href="https://woocommerce.com/products/woocommerce-paypal-payments/" target="_blank" class="button woocommerce-save-button">Learn more</a>
56+
</div>
57+
</div>
58+
</td>
59+
</tr>

0 commit comments

Comments
 (0)