• Resolved dipstar

    (@dipstar)


    Hello,

    Currently I’m looking for the way to pass SKU of purchased products to Stripe in metadata. By default, this parameter appears not to be supported.

    Is it possible to achive it with code snippet (adding some lines to functions.php)?

    Thank you very much.

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

    (@mrclayton)

    Hi @dipstar

    The Stripe plugin by default passes the product’s ID in the metadata of the PaymentIntent. You would need to add a unique key to the metadata array and make the value the SKU. Here is an example:

    add_filter('wc_stripe_order_meta_data', function($metadata, $order){
    	foreach ( $order->get_items( 'line_item' ) as $item ) {
    	    	$product = $item->get_product();
    		$metadata['sku-' . $product->get_id()] = $product->get_sku();
    	}
    	return $metadata;
    }, 10, 2);

    Kind Regards,

    Thread Starter dipstar

    (@dipstar)

    Working! We revised the code a little as ‘sku’ value always be static. Thanks for your great support.

    add_filter('wc_stripe_order_meta_data', function($metadata, $order){
    foreach ( $order->get_items( 'line_item' ) as $item ) {
    $product = $item->get_product();
    $metadata['sku'] = $product->get_sku();
    }
    return $metadata;
    }, 10, 2);

    Plugin Author Payment Plugins

    (@mrclayton)

    @dipstar just be aware that if the order has more than one product type you will only be getting the last value in the list of items since you’re overriding the sku key because it’s in a loop.

    Kind Regards

    hritikpatel

    (@hritikpatel)

    @dipstar How did you solved it? Where did placed this code? I’m also stuck on same issue… I want to send subtotal to stripe, How can I do it?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘I would like to pass SKU of purchased products to Stripe in metadata.’ is closed to new replies.