1

i'm trying to add product to the cart via PHP using this code,

$woocommerce->cart->add_to_cart(20);

the product is getting into the cart but i would like to add custom meta as shown on the image but i want to do that via PHP and not the backend

meta preview

Eli Y
  • 877
  • 16
  • 41

1 Answers1

5

So after bit of reading throughout the code. I've found this

$woocommerce->cart->add_to_cart($product, $quantity, $variation, array('foo'=>'bar') );

Eli Y
  • 877
  • 16
  • 41
  • 1
    well, i'm unsure that this works in the latest version of WooCommerce, so cannot confirm, but as far as i recall you can provide `null` to variation – Eli Y Sep 13 '16 at 13:34