How to Change Stripe Payment Details Description Text Without Plugin

how to change payment description in stripe

In this article, we will learn how to change the default payment descriptor in Stripe without any plugin, which gives way more control over the description text as compared to a plugin.

What you will learn today:

  • What is stripe payment descriptor text
  • Stripe payment intent request
  • How to change stripe payment details description text without plugin
  • Use product name as stripe transaction description
  • Use any custom field as payment description text
  • How to change stripe payment description in WooCommerce

What is Stripe payment details description text?

Stripe payment details or stripe transaction descriptor text is what you see on the Stripe Transactions page, for each transaction, in your stripe dashboard. It is also available on the individual stripe transaction page as shown below.

stripe payment details description text
stripe payment details description text on individual transaction page

This transaction description text is generated by WooCommerce while initiating a stripe transaction during checkout. By default WooCommerce generates this transaction descriptor by concatenating the website blog name & the order id.

For example, if your blog or website name is EcommerceBlog and the order number is 1210 then the default woocommerce stripe payment description text would become EcommerceBlog – Order 1210.

Now lets check how to change this woocommerce stripe payment details description text to whatever you want.

WooCommerce stripe payment intent request

Whenever a new checkout is initiated then woocommerce stripe payment gateway prepares a stripe payment intent request by calling this filter wc_stripe_generate_payment_request.

This payment request is POST request with data containing an array of customer information, order information, and some other useful information to process the transaction. Below is an example of woocommerce stripe payment intent request body.

2022-04-29T05:59:55+00:00 DEBUG 
====Stripe Version: 6.3.0====
====Start Log====
payment_intents request: Array
(
    [source] => src_1***************k
    [amount] => 50000
    [currency] => usd
    [description] => Dentalprenr - Order 1705
    [metadata] => Array
        (
            [customer_name] => ashvani kumar
            [customer_email] => t*******s@hotmail.com
            [order_id] => 1705
            [site_url] => https://******.wpengine.com
            [save_payment_method] => true
        )

    [capture_method] => automatic
    [payment_method_types] => Array
        (
            [0] => card
        )

    [setup_future_usage] => off_session
    [customer] => cus_L*********o
    [statement_descriptor] => DP-
)

====End Log====

As you can see from the data above that it contains a variable [desription] with value Dentalprenr – Order 1705, this is the actual payment details descriptor text used in Stripe.

What we will do that, we will change this value with our custom stripe description text before woocommerce sends it to Stripe by creating a new function and hook it with the wc_stripe_generate_payment_request filter.

Change stripe payment description without plugin

Put the following stripe payment details description code in your active theme’s functions.php file and change the CUSTOM_PAYMENT_DESCRIPTOR with your custom stripe payment descriptor.

add_filter( 'wc_stripe_generate_payment_request', 'the_wpbuddy_change_stripe_payment_description', 3, 10 );

function the_wpbuddy_change_stripe_payment_description( $post_data, $order, $prepared_source ) {

        $post_data['description'] = 'CUSTOM_PAYMENT_DESCRIPTOR' . $order->get_order_number();

    return $post_data;
}

This line $post_data[‘description’] = ‘CUSTOM_PAYMENT_DESCRIPTOR’ . $order->get_order_number(); tells the woocommerce to use this custom payment details description for Stripe. You can change it to anything you want.

Replace Woocommerce Stripe Payment Description With Product Name

If you want to show the product ordered name instead of the static descriptor text then use the following code. One thing to note that it would work best if the order contains only one product.

If there are multiple products in the order then this method would set the last product in the order as the stripe transaction description text.

add_filter( 'wc_stripe_generate_payment_request', 'the_wpbuddy_change_stripe_payment_description', 3, 10 );

function the_wpbuddy_change_stripe_payment_description( $post_data, $order, $prepared_source ) {
    
// Get and Loop Over Order Items
    foreach ( $order->get_items() as $item_id => $item ) {

       $product_name = $item->get_name();

    }

    $post_data['description'] = $product_name . ' - Order ' . $order->get_order_number();

    return $post_data;
}

For example, if have a product named “Rich Dad Poor Dad” then the above code would set the stripe transaction description text as “Rich Dad Poor Dad – Order 1000“. Following is a screenshot of my test orders to give you an idea of how it would look in real in stripe.

use product name as stripe payment details description text

Replace Woocommerce Stripe Payment Description With Product Custom Field

Now suppose your product name is very long then using it as description text is not a wise choice and stripe also might not like it and strip it to a particular length.

Then, solution to this is that you can give each product a short name to be used as stripe description text by creating a custom field of your choice.

For example, I created a custom field “stripe_name” and edited each product to give its own unique short name as shown below.

create product custom field in woocommerce

Now put the following code into your theme’s functions.php file and it would grab the value from the custom field and set it as stripe payment description. If you don’t specify this custom value then the code will use the product name as the description text.

add_filter( 'wc_stripe_generate_payment_request', 'the_wpbuddy_change_stripe_payment_description', 3, 10 );
function the_wpbuddy_change_stripe_payment_description( $post_data, $order, $prepared_source ) {
    // Get and Loop Over Order Items
    foreach ( $order->get_items() as $item_id => $item ) {

       $product_id = $item->get_product_id();
       $stripeName = "";
       $stripeName = strip_tags(get_post_meta($product_id,'stripe_name',true));
       if($stripeName == "" || $stripeName == null) {
            $stripeName = $item->get_name();
       }

    }

    $post_data['description'] = $stripeName . ' - Order ' . $order->get_order_number();

    return $post_data;
}

There are numerous other possibilities here. You can set almost anything as the custom stripe payment details description text. For example, you can:

  • set product’s category name as the stripe description text
  • set product’s tag as descriptor
  • use product’s slug or checkout page slug as the descriptor
  • set current date and time as the description text
  • even use customer’s info like location, ip address, etc

In a nutshell, you can customize the stripe descriptions text to whatever you can think of.

Let me know in comments if you liked my article or if you have any problem in implementing the solution.

Leave a Comment