• Resolved TC.K

    (@wp_dummy)


    In the stripe account payment table (the stripe account, not in the wp). There is a description field where displays the description like this :
    Order XXX From My SIte

    I don’t know how stripe generate that. My question is can I change this field from our end?

    Actually, I have added prefix to the order number, but Stripe not getting the order number, instead Stripe just use the original Order ID. All I want is to use the Order Number in this description field.

    I found there is a filter wc_stripe_order_meta_data, is this the field that in charge for the order details?
    Can I use this to change the order Id in the description?
    Like eg:

    
    add_filter('wc_stripe_order_meta_data', 'change_strip_desc',20,2);
    function change_strip_desc($meta_data, $order ){
        $meta_data['order_id'] = $order->get_order_number();
        return $meta_data;
    }
    

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Payment Plugins

    (@mrclayton)

    Hi @wp_dummy,

    Thank you for contacting us. The wc_stripe_order_meta_data filter changes the metadata, but the description field is its own property. The plugin already includes the order_id and order_number in the metadata and I don’t recommend you change order_id because the plugin depends on that metadata for other processes.

    You should use the filter wc_stripe_payment_intent_args.

    Example:

    add_filter('wc_stripe_payment_intent_args', function($args, $order){
        $args['description'] = 'My customer description';
        return $args;
    }, 10, 2);

    However, the Stripe plugin already uses the order number in the description which you can see in the code at the following link:

    https://docs.paymentplugins.com/wc-stripe/api/source-class-WC_Stripe_Payment.html#218

    Kind Regards,

    Thread Starter TC.K

    (@wp_dummy)

    yes, you are right.
    From the source code it use $order->get_order_number() to get the order number in the description.
    But it still not pick up the order number in description.

    For you info, it is dynamic order number, which will depends on customer role to determine the prefix.

    I create the an order field that hold this prefix, upon order is placed. eg:

    add_action('woocommerce_new_order', 'dynamic_o_number',50);
    function dynamic_o_number($order_id){
        $user_id = $order->get_customer_id();
        $user_roles = array();
        if($user_id){
            $user = get_userdata( $user_id );
            $user_roles = $user->roles;
        }
       if ( in_array(   'special_role' , $user_roles) ) {
           update_post_meta( $order_id, 'order_numb' , 'SPC-'.$order_id );
       }else{
           update_post_meta( $order_id, 'order_numb' , 'NOC-'.$order_id );
       }
    }

    And in the woocommerce_order_number' filter:

    add_filter( 'woocommerce_order_number', 'change_woocommerce_order_number',20, 2 );
    function change_woocommerce_order_number( $order_id, $order ) {
          return $order->get_meta( 'order_numb', true);
    }

    This works in everywhere that called out the order number, but not in stripe. This is where I don’t understand.
    I wonder how Stripe process the checkout?
    The only reason that I can think of is Stripe bypassed the woocommerce_new_order when checkout. Is it so?

    Plugin Author Payment Plugins

    (@mrclayton)

    @wp_dummy,

    Stripe does not bypass any of the WC code. Check to see when you are adding your function for the woocommerce_order_number filter. Perhaps you aren’t adding your function before WooCommerce calls the Stripe plugin to process the payment.

    I think it’s safe to say your function is not being called since the description contains the order ID in it.

    Kind Regards,

    Thread Starter TC.K

    (@wp_dummy)

    But in your plugin:

    public function add_order_description( &$args, $order ) {
            $args['description'] = sprintf( __( 'Order %1$s from %2$s', 'woo-stripe-payment' ), $order->get_order_number(), get_bloginfo( 'name' ) );
        }

    It uses $order->get_order_number() to get the order number. It should get the number from woocommerce_order_number filter.

    Btw, I updated the filter, it still not getting the order number correctly:

    add_filter( 'woocommerce_order_number', 'change_woocommerce_order_number',20, 2 );
    function change_woocommerce_order_number( $order_id, $order ) {
          if ($order->get_meta( 'order_numb', true)){
             return $order->get_meta( 'order_numb', true);
          }
          return $order_id;
    }

    Seem it not getting value from $order->get_meta( 'order_numb', true) , but in other place, it displayed correctly.
    Possible it is not fire woocommerce_new_order during checkout with stripe? If so, but why?

    Plugin Author Payment Plugins

    (@mrclayton)

    @wp_dummy,

    If you look at the WooCommerce code you will see that WC_Order::get_order_number is a wrapper for the filter woocommerce_order_number. That ensures that the filter is called every time the order number is accessed.

    Here is a link to the WC source code showing the use of that filter:

    https://woocommerce.github.io/code-reference/files/woocommerce-includes-class-wc-order.html#source-view.479

    You are probably adding your customer function change_woocommerce_order_number too late in the filter sequence. Add your function during the init action.

    Kind Regards,

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘change payment description in stripe account dashboard’ is closed to new replies.