Last active
May 15, 2021 18:40
-
-
Save wpmudev-sls/d0298dfc427dfe83493d248dfe6dd1a4 to your computer and use it in GitHub Desktop.
[Forminator] - PayPal order Description.
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] - PayPal order Description and NO_SHIPPING | |
* Plugin URI: https://premium.wpmudev.org/ | |
* Description: Add description to PayPal orders. Compatible only with Forminator 1.14.7 and higher. Please test this snippet on a staging site before any forminator update (or any general update) | |
* Task: SLS-1435 | |
* Author: Panos Lyrakis @ WPMUDEV | |
* Author URI: https://premium.wpmudev.org/ | |
* License: GPLv2 or later | |
*/ | |
/** | |
* NOTE | |
* For Forminator versions prior to 1.14.7 you can try https://gist.github.com/wpmudev-sls/5b8982228b9880c7ee6fc7c0c34dcdf0 | |
*/ | |
if ( ! defined( 'ABSPATH' ) || ( defined( 'WP_CLI' ) && WP_CLI ) ) { | |
return; | |
} | |
add_filter( | |
'http_request_args', | |
function( $parsed_args, $url ){ | |
$body = ( is_array( $parsed_args ) && isset( $parsed_args[ 'body' ] ) ) ? json_decode( $parsed_args[ 'body' ] ) : null; | |
if ( ! preg_match( '/^https:\/\/api.(sandbox\.|)paypal.com\/v2\/checkout\/orders$/', $url ) || is_null( $body ) ) { | |
return $parsed_args; | |
} | |
if ( isset( $body->purchase_units ) ) { | |
// Set description. | |
$body->purchase_units[0]->description = "Some description"; | |
// Add NO_SHIPPING. | |
$body->application_context = new stdClass(); | |
$body->application_context->shipping_preference = 'NO_SHIPPING'; | |
} | |
$body = json_encode( $body ); | |
$parsed_args[ 'body' ] = $body; | |
return $parsed_args; | |
}, | |
20, 2 | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am absolutely not a WP expert, but I am currently working on this one website as a favor and I got this to work by placing it in the
/public_html/wp-content/mu-plugins
directory :)