Skip to content

Instantly share code, notes, and snippets.

@wpmudev-sls
Last active May 15, 2021 18:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpmudev-sls/d0298dfc427dfe83493d248dfe6dd1a4 to your computer and use it in GitHub Desktop.
Save wpmudev-sls/d0298dfc427dfe83493d248dfe6dd1a4 to your computer and use it in GitHub Desktop.
[Forminator] - PayPal order Description.
<?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
);
@sixeyeco
Copy link

Would you please tell me which page to edit? Or do I upload this page to a folder?

@jplewa
Copy link

jplewa commented May 15, 2021

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 :)

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