Skip to content

Add to Cart tag

The tag for adding items to the cart

The tag

{exp:reinos_store:add_to_cart}

Tag Parameters

Below are the Tag Parameters. Those parameters can be used in the tag described above

return_url

The return url, default to the current url

return_url=""

sku

The SKU for a product. If omitted, it allows you to add multiple lines of the same products in to your cart.

sku=""

entry_id

Set the entry_id of your product. This way we can reference the product to your entry.

entry_id=""

name

Set your product name

name=""

price

Set the price of the product.

price="0.00"

sale_price

Set the sales price of the product. This will be the price for the product and you can show this in your cart where for example you strike-through the {price}.

sale_price="0.00"

tax_rate

Set the tax.

This can either low or high and load the value that has been set in your settings

If omit the param, it will fallback on the default tax rate set in the settings.

tax_rate="low"

weight

Set the weight of the product. Mostly used when using the Shipping module

product_price="70" {!-- This set a weight of 70kg or 70lbs --}

clear_cart

When adding a product, your can clear the cart to have a cart with always one product.

clear_cart="no"

disable_shipping

If you have no shipping cost, you can disable it for a product

disable_shipping="no"

form_class

Set the form class

form_class=""

form_id

Set the form id

form_id=""

parent_order_item_id

Set the order Item Id that you want to reference as a parent item.

This is normally used when you reorder an item or renew for virtual products

parent_order_item_id="0"

custom_fields:[your-field-name]

Set custom fields

custom_fields:test="value"
custom_fields:or_an_other_value="value"

Input fields

qty

<input name="qty" value="1"/><br>

note

<input name="note" value=""/><br>

custom_fields

<input name="custom_fields[yet_another]" value="custom value"/><br>
<input name="custom_fields[and_another]" value="other custom value"/><br>

Tag Variables

error:invalid_price

Return the error when an invalid price is given.

{if error:invalid_price}
    <p style="color:red;">You have entered an invalid price</p>
{/if}

error:invalid_sale_price

Return the error when an invalid sales price is given.

{if error:invalid_sale_price}
    <p style="color:red;">You have entered an invalid sales price</p>
{/if}

Example

Below a small example how you can add a product to your cart

{exp:reinos_store:add_to_cart
  form_class="space-y-3"
  entry_id="{entry_id}"
  sku="{entry_id}"
  name="{title}"
  price="{product_price}"
  sale_price="{product_sale_price}"
  weight="{product_weight}"
  disable_shipping="{product_disable_shipping}"
  return_url="reinos_store/cart"
  tax="high"
  {!--Custom fields via prop --}
  custom_fields:test="test custom field"
}

  {if error:invalid_price}
    <p style="color:red;">You have entered an invalid price</p>
  {/if}

  {if error:invalid_sale_price}
    <p style="color:red;">You have entered an invalid sale price</p>
  {/if}
    
  {if error:out_of_stock}
    <p style="color:red;">There is not enough stock</p>
  {/if}

  <div class="flex flex-col space-y-1">
    <label class="font-medium">Custom Field</label>
    <input class="input" type="text" name="custom_fields[field_from_input]" placeholder="custom field"/>
  </div>

  <div class="flex flex-col space-y-1">
    <label class="font-medium" for="qty">Aantal</label>
    <input class="input" type="number" id="qty" name="qty" value="1"/><br>

    {!-- a simple note --}
    <label class="font-medium" for="note">Aantal</label>
    <input class="input" type="text" id="note" name="note" value=""/><br>

    {!-- You can also update a custom field for an cart item here --}
    {!-- "field_from_input" is here the name of the custom field --}
    <input class="border p-1 rounded" value="{exp:reinos_store:custom_cart_item_field_value cart_id="{cart:id}" field="field_from_input"}" name="custom_fields[{cart:id}][field_from_input]">
  </div>
    
  <input type="submit" class="button" value="Add to Cart"/>
{/exp:reinos_store:add_to_cart}