Support » Plugin: WooCommerce » How to post to add_to_cart

  • We are using WooCommerce 2.0.10 on WP 3.5.1.
    I have a client that requires a bundled product.
    I have the WooCommerce bundled product add-on.
    The client wants to offer 4 SKU’s within the bundle, which also has its own SKU.
    The sku’s in the bundle vary in size and bundle quantity. Bundle quantity has been added as an attribute to facilitate the variation.

    A shopper may select any number or size of the sku’s as long as the combined total of items selected does not exceed 18. We then sell the bundle for a fixed price.

    The woocommerce bundle add-on does not allow for quantity variations.
    I assume because they didn’t want to write the code that would check for a bundle item total.

    I have a Formidable form that handles this part using jQuery.
    Where I am stuck is in how to hand off the filled in form to WooCommerce.

    My functions.php has the following:

    function add_to_cart_action_fbwd( $url = false ) {
    // per Gerhard use $woocommerce->cart->add_to_cart( $product_id, $quantity = 1, $variation_id = '', $variation = '', $cart_item_data = array() )
    	global $woocommerce;
    	$quantity       = (isset($_REQUEST['qty'])) ? (int) $_REQUEST['qty'] : 1;
    	$product_id     = (int) apply_filters('woocommerce_add_to_cart_product_id', $_REQUEST['pid']);
    	$vid            = (int) apply_filters('woocommerce_add_to_cart_product_id', $_REQUEST['vid']);   
    	if ($vid > 0) $woocommerce->cart->add_to_cart( $product_id, $quantity, $vid );
    	else $woocommerce->cart->add_to_cart( $product_id, $quantity );
    }//end of function definition
    add_action('init', 'woocommerce_add_to_cart', 'add_to_cart_action_fbwd');

    The code never seems to fire.
    The site page loads the form via a shortcode and the woocommerce piece with a shortcode of [product_page sku=”tmpbndl-18″]

    The problem with approaching the processing this way is that I wind up with competing buttons. The jQuery is tied to the submit button.

    How can I tie it to the add to cart button?
    I could probably move the quantity validation jQuery code to the add_to_cart_fbwd function, if I could get it to process.

    The WooCommerce API lists lots of actions and hooks, but offers no strategy for how or when or in what context to use them.

    Any help would be appreciated.

  • The topic ‘How to post to add_to_cart’ is closed to new replies.