• Resolved insertdelete

    (@insertdelete)


    I can see in line 355 of woocommerce-gateway-stripe/includes/abstracts/abstract-wc-stripe-payment-gateway.php:

    $post_data['description'] = sprintf( __( '%1$s - Order %2$s', 'woocommerce-gateway-stripe' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), $order->get_order_number() );

    I would like to prefix the description with the product SKU. I have modified my site to only allow one product per order with this function:

    add_filter( 'woocommerce_add_to_cart_validation', 'only_one_in_cart', 99, 2 );
    function only_one_in_cart( $passed, $added_product_id ) {
    // empty cart first: new item will replace previous
    wc_empty_cart();
    return $passed;
    }

    I’m not sure how to override this with a hook. Would anyone be able to assist?

    The reason I want to do this is because Stripe payout exports do not include metadata fields, so I cannot financially track which product exactly has been purchased, otherwise I would just store the SKU in the extra metadata fields. The payout exports do however show the description field, so if I can get the SKU in there then it would make life a lot easier.

    Thank you

    edit: I see there is a filter for this function, wc_stripe_generate_payment_request, https://github.com/woocommerce/woocommerce-gateway-stripe/blob/c1ac09f5e11f68d4f07eb7585bd06722351a8195/includes/class-wc-gateway-stripe.php#L413

    • This topic was modified 6 years, 1 month ago by insertdelete.
    • This topic was modified 6 years, 1 month ago by insertdelete.
    • This topic was modified 6 years, 1 month ago by insertdelete.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter insertdelete

    (@insertdelete)

    Ok I think I’ve managed to figure it out.

    add_filter( 'wc_stripe_generate_payment_request', 'filter_wc_stripe_payment_descriptionmod', 3, 10 );
    function filter_wc_stripe_payment_descriptionmod( $post_data, $order, $source ) {
    	foreach( $order->get_items() as $item_id => $line_item ){
    		$item_data = $line_item->get_data();
    		$product = $line_item->get_product();
    		$product_sku = $product->get_sku();
    	}
    	$post_data['description'] = sprintf( __( '%1$s | %2$s' ), $product_sku, $post_data['description'] );
    	return $post_data;
    }

    Lines 3-7 could probably be done differently, but this works for me since I have the function in place from my first post.

    I’d still appreciate anyone else’s feedback and hope this ends up helping someone.

    • This reply was modified 6 years, 1 month ago by insertdelete.
    • This reply was modified 6 years, 1 month ago by insertdelete.
    Mike W

    (@nixiack8)

    Hi @insertdelete,

    It appears that you were able to get it to work for your site, that is great! I will go ahead and mark this thread as Resolved as it works for you, and others might be able to look at it and test on their site.

    Each site is different though, so what might work on your site may not work on another – that being said, it is a very solid ground to start from. Thank you for that!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Modify the payment description’ is closed to new replies.