Last active
February 23, 2023 09:30
-
-
Save wpmudev-sls/2d5e740a9c6024bfefde8aa44ca02b86 to your computer and use it in GitHub Desktop.
[Forminator] - Use NO_SHIPPING in PayPal. This snippet removes the shipping label (Ship To) from PayPal's popup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: [Forminator] - Use NO_SHIPPING in PayPal | |
* Plugin URI: https://premium.wpmudev.org/ | |
* Description: This snippet removes the shipping label (Ship To) from PayPal's popup | |
* Task : SLS-2311 | |
* Author: Panos Lyrakis @ WPMUDEV | |
* Author URI: https://premium.wpmudev.org/ | |
* License: GPLv2 or later | |
*/ | |
if ( ! defined( 'ABSPATH' ) || ( defined( 'WP_CLI' ) && WP_CLI ) ) { | |
return; | |
} | |
// We're using the `forminator_paypal_request_sslverify` filter to make sure this only affects this specific request. | |
add_filter( | |
'forminator_paypal_request_sslverify', | |
function( $ssl_verify ) { | |
add_filter( | |
'http_request_args', | |
function( $parsed_args, $url ) { | |
// It's most likely json but we still need to confirm. | |
if ( isset( $parsed_args['headers']['Content-Type'] ) && 'application/json' === $parsed_args['headers']['Content-Type'] ) { | |
$body = json_decode( $parsed_args['body'], true ); | |
$body['application_context'] = array( 'shipping_preference' => 'NO_SHIPPING' ); | |
$parsed_args['body'] = json_encode( $body ); | |
} else { | |
$parsed_args['body']['application_context'] = array( 'shipping_preference' => 'NO_SHIPPING' ); | |
} | |
return $parsed_args; | |
}, | |
10, | |
2 | |
); | |
return $ssl_verify; | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is giving me
An error occurred while processing the form. Please try again