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

elibyy
  • 859
  • 17
  • 40

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') );

elibyy
  • 859
  • 17
  • 40
  • 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 – elibyy Sep 13 '16 at 13:34