The "Add to Cart" button is not adding items to the shopping cart.


A client of ours is currently using the MarketPress eCommerce platform. Due to the nature of the product, we needed to create a custom template to handle the configuration of the product that was being ordered. The issue is that while everything displays properly on the front end, upon adding the item to the shopping cart by clicking the "add to cart" button (which seemed to work on previous version of this eCommerce plugin, i.e. before version, a) the page redirects to the cart page and b) no items are added to the shopping cart. Here is what the custom form looks like on our custom page template:

<form class="mp_buy_form" method="post" data-ajax-url="" action="">
<div id="signUpArea"></div>
<input type="submit" class="mp_button mp_button-addcart" name="addcart" value="ADD TO CART" />

I made the data-ajax-url similar to the default add to cart functionality, but nothing seems to be happening still. When I try to view my cart, it is always empty. Has there been a fundamental change regarding to the add to cart functionality recently? Thank you for pointing me in the right direction.


  • Vinod Dalvi

    Hi Shane,

    I hope you are well today and thanks for posting on the forum.

    Are your default products working fine without using custom page template and the custom form?

    Could you please try using the following code replacing your shared code?

    <form id="mp-buy-product-5831-form" class="mp_form mp_form-buy-product " method="post" data-ajax-url="" action="" novalidate="novalidate">
    	<input type="hidden" name="product_id" value="5831">
    			<div class="mp_product_options_atts">
    				<div class="mp_product_options_att">
    					<strong class="mp_product_options_att_label">Quantity</strong>
    					<div class="mp_form_field mp_product_options_att_field">
    						<label class="mp_form_label mp_product_options_att_input_label" for="mp_product_options_att_quantity"></label>
    						<input id="mp_product_options_att_quantity" class="mp_form_input mp_form_input-qty required digits" min="1" max="100" type="number" name="product_quantity" value="1" aria-required="true">
    					</div><!-- end mp_product_options_att_field -->
    				</div><!-- end mp_product_options_att -->
    			</div><!-- end mp_product_options_atts -->
    			<button class="mp_button mp_button-addcart" type="submit" name="addcart">Add To Cart</button>

    Change the product id 5831 in the above code to the product id on your site.

    Best Regards,
    Vinod Dalvi

  • Nathan Onn

    I guess is mp-cart.js didn't called in your custom template. You'll need that file to trigger the ajax function for the "Add to Cart" button.

    Unlike in the previous version of MarketPress, version 3 will only enqueue all cart related css & js when needed. Hence, simply copy and paste codes from buy_button() into your custom template won't work. You'll need to call all the cart related css & js - so that the "Add to cart" process can run properly.

    So, here's the solution - simply add the following codes into functions.php of your theme:

    add_action( 'wp_enqueue_scripts' , 'enforce_mp_cart_scripts' , 15 );
    function enforce_mp_cart_scripts() {
    	$mp_sc = MP_Short_Codes::get_instance();

    That way you'll enforce all marketpress frontend styles & scripts into all pages, regardless of whether MarketPress related elements is in the page.

    Alternatively, you can also just add these code to the top of your custom template:

    $mp_sc = MP_Short_Codes::get_instance();

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.