Skip to content

Instantly share code, notes, and snippets.

@wpmudev-sls
Last active February 23, 2023 09:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpmudev-sls/2d5e740a9c6024bfefde8aa44ca02b86 to your computer and use it in GitHub Desktop.
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
<?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;
}
);
@mbejda
Copy link

mbejda commented Feb 23, 2023

This is giving me An error occurred while processing the form. Please try again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment