Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter truongdang

    (@truongdang)

    For posterity’s sake. These are the functions I created and used:
    This function searches the corresponding Woo Commerce Product ID which is attached to the event-postID (connected to the event-area, which is connectet to the woocommerce product).

    function getProductID($eventID){
    	global $wpdb;
    	$result1 = $wpdb->get_results('SELECT meta_value FROM wp_2_postmeta WHERE meta_key = "_event_area_id" AND post_ID = '.$eventID);
    	$eventereaID = $result1[0]->meta_value;
    
    	$result2 = $wpdb->get_results('SELECT meta_value FROM wp_2_postmeta WHERE meta_key = "_pricing_options" AND post_ID = '.$eventereaID);
    	$productID = $result2[0]->meta_value;
    
    	if($productID>0){
    		return $productID;
    	}
    	return false;
    }

    And this function adds an event programmatically

    function add_ticket_to_cart($eventid, $ticket_type_id, $count ){
    	global $woocommerce;
    	$data = array(
    		'event_id' => $eventid,
    	);
    
    	if ( is_object( $woocommerce->cart ) ) {
    		// Generate a ID based on product ID, variation ID, variation data, and other cart item data
    		$cart_id = $woocommerce->cart->generate_cart_id( $ticket_type_id, '', '', $data );
    
    		// See if this product and its options is already in the cart
    		$cart_item_key = $woocommerce->cart->find_product_in_cart( $cart_id );
    		if ($count == 0) {
    			if ($cart_item_key) {
    				$woocommerce->cart->set_quantity( $cart_item_key, 0 );
    			}
    		} else {
    			if ($cart_item_key) {
    				$woocommerce->cart->set_quantity( $cart_item_key, $count );
    			} else {
    				$woocommerce->cart->add_to_cart( $ticket_type_id, $count, '', '', $data );
    			}
    		}
    	}
    	return $cart_id;
    }

    Thread Starter truongdang

    (@truongdang)

    Thanks for the help. This was exactly the lead I needed to accomplish this.

    What I did, I created a new function based on reserve_current_user.

    I searched with my own wp sql query which event+productid combination I want to add to the cart. The function is placed an ajax/php file, which I can call from jquery/javascript.

    Thread Starter truongdang

    (@truongdang)

    What I’ve found so far in
    assets/js/features/event-area/ui.js

    Is the EATicketSelection which can be used to print out the while ticket-selectform, it automatically uses the event/post ID for construction and it creates all event-listeners for adding/updating and removing events on the form.

    What I really would like to know is which kind of ajax call can be used to push an event to the cart with JS/PHP or ajax when I have an event-id.

Viewing 3 replies - 1 through 3 (of 3 total)