Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Add a description to the Charge event triggered by a Direct Stripe Subscription

How to add a description to a charge triggered by a subscription of Direct Stripe WordPress plugin plugin

First steps from your Stripe dashboard

  • Log in the Stripe Dashboard

  • Add a webhook endpoint in Developers -> Webhooks -> ( Add endpoint ) button

Steps with the custom code to be edited and installed as a WordPress plugin

  • Edit the code of ds-custom-code.php file
  • Insert your own Secret API key
  • Edit with your own pricing plan ID
  • Edit with the decription you want to add to charges triggered by the Subscription
  • Zip the file

Last steps from your WordPress dashboard

  • Go to Plugins -> Add new
  • Click the Upload plugin button
  • Select the Zipped file of ds-custom-code.php
  • Activate the plugin
* Plugin Name: DS custom code
* Author: Nicolas Figueira
* Description: Add description to Charge triggered by Subscription
* Plugin URI:
* This code is an add-on of Direct Stripe WordPress plugin
* Explanation at
add_action( 'rest_api_init', function () {
register_rest_route( 'direct-stripe/v1', '/subscription-charge-succeeded', array(
'methods' => 'POST',
'callback' => 'ds_add_description',
) );
function ds_add_description(){
if ( ! class_exists('Stripe\Stripe')) {
require_once( DSCORE_PATH . 'vendor/autoload.php' );
\Stripe\Stripe::setApiKey('Stripe_secret_API_Key'); // EDIT WITH YOUR OWN API KEY
$input = @file_get_contents('php://input');
$event = json_decode($input);
if( $event->data->object->lines->data[0]->plan->id === "pricing_plan_id" ) { // EDIT with the pricing plan ID used in the Direct Stripe Button
$charge = \Stripe\Charge::retrieve( $event->data->object->charge );
$charge->description = "Webhook edited description"; //EDIT with the description you want to add to charges
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.