Forum

Thread tagged as: Problem

Pass product variant to Stripe meta data

The following is code I've been using for a while now to pass on to stripe details about the order as meta data. I've just tried to add the product variant information but I get an undefined index on productVariantDesc. If I do a print_r of $cart_items I see the information I want listed under productVariantDesc so that's where I got that from. (Title and SKU work fine)

$cart = perch_shop_cart(['skip-template'=>true]);
    $cart_items = $cart['items'];

    foreach($cart_items as $item) {
      $product_titles[] = $item['title'];
      $product_skus[] = $item['sku'];
      $product_variants[] = $item['productVariantDesc'];
    }

    $product_title = implode(', ', $product_titles);
    $product_sku = implode(', ', $product_skus);
    $product_variant = implode(', ', $product_variants);
Stephen Turvey

Stephen Turvey 0 points

  • 3 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

What are you then doing with $cart_items ?

Passing it in to the stripe meta data

// stripe data
    perch_shop_checkout('stripe', [
    'return_url' => $return_url,
    'cancel_url' => $cancel_url,
    'token' => perch_post('stripeToken'),
    'receipt_email' => $customer_email,
    'metadata' => [
        'email' => $customer_email,
        'name' => $customer_name,
        'product(s)' => $product_title,
        'sku(s)' => $product_sku,
        ],
    ]);
Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

Hello Stephen,

$item['productVariantDesc'] doesn't exist indeed. A PerchShop_Product object $item['Product'] should.

Though I think the productVariantDesc is returned in a protected property so you wouldn't be able to get it this way as far as I know.