• Resolved Nikolay Nikolov

    (@nnikolov)


    Hello.

    Thank you for your great plugin. I am making a link that adds a product to the cart with ajax (to use on some page that is not a product page). I am using WC()->cart->add_to_cart( 123 ) to add a product to cart, but I also want to set some of its extra options to a certain value (so it is as if they were chosen before adding to cart). Can you point me to the correct hook to use for that, is it woocommerce_get_item_data?

    Regards.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author ThemeHigh

    (@themehigh)

    Yes, we are using that same hook to add extra options as product(item) meta data.

    Unfortunately, there is no direct option available in the lite version of our plugin to achieve this.

    However, you can refer to the following code snippets to fulfill your requirements.

    add_filter( 'woocommerce_add_cart_item_data', 'add_custom_data_to_cart', 10, 2 );
    
    function add_custom_data_to_cart( $cart_item_data, $product_id ) {
    // Add custom data to the cart item data array
    $cart_item_data['custom_data'] = 'Some custom data';
    return $cart_item_data;
    }
    
    // extra options data are stored in [‘thwepof_options’] key of cart_item_data array/object
    $cart_item_data['thwepof_options'] = $extra_cart_item_data;

    Thank you!

    Thread Starter Nikolay Nikolov

    (@nnikolov)

    Ah, its woocommerce_add_cart_item_data, got it, thanks!

    Plugin Author ThemeHigh

    (@themehigh)

    Great!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Link that adds to cart with pre-selected options’ is closed to new replies.