Woo-commerce add_to_cart function with custom data


Please find below code…

/*Custom data*/
$cart_item_data = array(‘inputurl’ => “data”);

/*Variation*/
$variation = array(‘attribute_pa_color’ => $color);

WC()->cart->add_to_cart( $product_id, $quntity, $variation_id, $variation , $cart_item_data );

/*Add custom data using filter hook wordpress*/
Put below code in functions.php

add_filter( ‘woocommerce_add_cart_item_data’,’add_cart_item_data’, 10, 3 );
function add_cart_item_data( $cart_item_meta, $product_id, $variation_id ) {
// function code
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s