Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[Pro Sites] - Hides the second available gateway when the Monthly and Quarterly periods are selected
<?php
/**
* Plugin Name: [Pro Sites] - Gateways Per Period
* Plugin URI: https://premium.wpmudev.org/
* Description: Hides the second available gateway when the Monthly and Quarterly periods are selected
* Author: Panos Lyrakis @ WPMUDEV (modified by Adam Czajczyk)
* Author URI: https://premium.wpmudev.org/
* License: GPLv2 or later
*/
add_action( 'wp_footer', function(){
global $psts;
if ( ! is_page() || get_the_ID() != $psts->get_setting( 'checkout_page' ) ) {
return;
}
?>
<script type="text/javascript">
(function($,d){
var WPMUDEV_PS_Man_Gateways = {
ps_selector : '',
target_gateway : '',
neutral_gateway : '',
init : function(){
this.ps_conatiner = $( '#prosites-checkout-table' );
this.ps_selector = $( '.period-selector-container input' );
this.target_gateway = $( '#gateways ul li:eq( 1 )' );
this.neutral_gateway = $( '#gateways ul li:eq( 0 )' );
WPMUDEV_PS_Man_Gateways.monitor_change();
$(d).on( 'change', this.ps_selector, function(){
WPMUDEV_PS_Man_Gateways.monitor_change();
});
$(d).ajaxComplete(function( event, xhr, settings ) {
const action = WPMUDEV_PS_Man_Gateways.get_action( 'action', settings.data );
if( 'check_prosite_blog' === action ){
WPMUDEV_PS_Man_Gateways.init();
}
});
},
monitor_change : function() {
let val = this.ps_conatiner.attr( 'data-period' );
if ( '12' != val ) {
this.target_gateway.hide();
if ( ! this.neutral_gateway.hasClass( 'ui-state-active' ) ) {
this.neutral_gateway.find( 'a' ).click();
}
}
else {
this.target_gateway.show();
}
},
get_action: function( name, url ){
if ( ! url ){
return '';
}
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp( name + "(=([^&#]*)|&|#|$)" ),
results = regex.exec( url );
if ( ! results ) return null;
if ( ! results[2] ) return '';
return decodeURIComponent( results[2].replace(/\+/g, " ") );
}
};
$(d).ready(function(){
WPMUDEV_PS_Man_Gateways.init();
});
})(jQuery, document);
</script>
<?php
});
<?php
/**
* Plugin Name: [Pro Sites] - Gateways Per Period
* Plugin URI: https://premium.wpmudev.org/
* Description: Hides the second available gateway when the Monthly and Quarterly periods are selected
* Author: Panos Lyrakis @ WPMUDEV
* Author URI: https://premium.wpmudev.org/
* License: GPLv2 or later
*/
add_action( 'wp_footer', function(){
global $psts;
if ( ! is_page() || get_the_ID() != $psts->get_setting( 'checkout_page' ) ) {
return;
}
?>
<script type="text/javascript">
(function($,d){
var WPMUDEV_PS_Man_Gateways = {
ps_selector : '',
target_gateway : '',
neutral_gateway : '',
init : function(){
this.ps_selector = $( '#prosites-checkout-table select.chosen' );
this.target_gateway = $( '#gateways ul li:eq( 1 )' );
this.neutral_gateway = $( '#gateways ul li:eq( 0 )' );
WPMUDEV_PS_Man_Gateways.monitor_change();
$(d).on( 'change', this.ps_selector, function(){
WPMUDEV_PS_Man_Gateways.monitor_change();
});
$(d).ajaxComplete(function( event, xhr, settings ) {
const action = WPMUDEV_PS_Man_Gateways.get_action( 'action', settings.data );
if( 'check_prosite_blog' === action ){
WPMUDEV_PS_Man_Gateways.init();
}
});
},
monitor_change : function() {
let val = this.ps_selector.val();
if ( 'price_12' != val ) {
this.target_gateway.hide();
if ( ! this.neutral_gateway.hasClass( 'ui-state-active' ) ) {
this.neutral_gateway.find( 'a' ).click();
}
}
else {
this.target_gateway.show();
}
},
get_action: function( name, url ){
if ( ! url ){
return '';
}
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp( name + "(=([^&#]*)|&|#|$)" ),
results = regex.exec( url );
if ( ! results ) return null;
if ( ! results[2] ) return '';
return decodeURIComponent( results[2].replace(/\+/g, " ") );
}
};
$(d).ready(function(){
WPMUDEV_PS_Man_Gateways.init();
});
})(jQuery, document);
</script>
<?php
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.