Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving performance by no longer filtering gateway option #99

Merged
Merged
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
2 changes: 1 addition & 1 deletion js/pmpro-pay-by-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function pmpropbc_isLevelFree() {
}

function pmpropbc_isCheckGatewayChosen() {
if(jQuery('input[name=gateway]:checked').val() === 'check') {
if(jQuery('input[name=gateway]:checked').val() === 'check' || pmpropbc.check_only === '1') {
return true;
} else {
return false;
Expand Down
28 changes: 23 additions & 5 deletions pmpro-pay-by-check.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ function pmpropbc_checkout_boxes()
</div> <!-- end pmpro_checkout-fields -->
</div> <!-- end #pmpro_payment_method -->
<?php
} elseif ( $gateway_setting != "check" && $options['setting'] == 2 ) { ?>
<input type="hidden" name="gateway" value="check" />
<?php
}
}
add_action("pmpro_checkout_boxes", "pmpropbc_checkout_boxes", 20);
Expand Down Expand Up @@ -235,6 +238,15 @@ function pmpropbc_enqueue_scripts() {
//get original checkout level and another with discount code applied
$pmpro_nocode_level = pmpro_getLevelAtCheckout(false, '^*NOTAREALCODE*^');
$pmpro_code_level = pmpro_getLevelAtCheckout(); //NOTE: could be same as $pmpro_nocode_level if no code was used

// Determine whether this level is a "check only" level.
$check_only = 0;
if ( ! empty( $pmpro_code_level->id ) ) {
$options = pmpropbc_getOptions( $pmpro_code_level->id );
if ( $options['setting'] == 2 ) {
$check_only = 1;
}
}

//restore these values
$pmpro_msg = $omsg;
Expand All @@ -247,6 +259,7 @@ function pmpropbc_enqueue_scripts() {
'pmpro_review' => (bool)$pmpro_review,
'is_admin' => is_admin(),
'hide_billing_address_fields' => apply_filters('pmpro_hide_billing_address_fields', false ),
'check_only' => $check_only,
)
);

Expand Down Expand Up @@ -274,11 +287,15 @@ function pmpropbc_pmpro_valid_gateways($gateways)
}
add_filter("pmpro_valid_gateways", "pmpropbc_pmpro_valid_gateways");

/*
Force check gateway if pbc_setting is 2
*/
/**
* Force check gateway if pbc_setting is 2.
*
* @deprecated TBD Now handled similarly to pbc_setting 1.
*/
function pmpropbc_pmpro_get_gateway($gateway)
{
_deprecated_function( __FUNCTION__, 'TBD' );

$level = pmpro_getLevelAtCheckout();

if ( ! empty( $level->id ) )
Expand All @@ -291,8 +308,6 @@ function pmpropbc_pmpro_get_gateway($gateway)

return $gateway;
}
add_filter('pmpro_get_gateway', 'pmpropbc_pmpro_get_gateway');
add_filter('option_pmpro_gateway', 'pmpropbc_pmpro_get_gateway');

/*
Need to remove some filters added by the check gateway.
Expand All @@ -316,6 +331,9 @@ function pmpropbc_init_include_billing_address_fields()
add_filter('pmpro_include_billing_address_fields', '__return_false', 20);
add_filter('pmpro_include_payment_information_fields', '__return_false', 20);

// Need to also specifically remove them for Stripe.
remove_filter( 'pmpro_include_payment_information_fields', array( 'PMProGateway_stripe', 'pmpro_include_payment_information_fields' ) );

//Hide the toggle section if the PayPal Express Add On is active
remove_action( "pmpro_checkout_boxes", "pmproappe_pmpro_checkout_boxes", 20 );
} else {
Expand Down