Cart Tags
From Shopp Documentation
The cart shopp() tags provide a way to display current information in the shopper's cart and interface elements that give the shopper controls to manage their shopping cart. Shopp's cart tags can be used in most any theme file, including WordPress theme files such as header.php, sidebar.php, or footer.php. In Shopp's template files, the cart tags are usually found in the cart.php and sidecart.php template files.
url
- Overview
-
<?php shopp('cart','url'); ?>
Displays the shopping cart page permalink for use in href attributes of HTML anchor <a> tags or the action attribute of a <form> tag.
- Options
-
- return: when set to true, this option forces the tag to return the value instead of displaying the value to the page. This is useful when you need to write php logic that needs to evaluate the "value" of the tag, or to modify the value before displaying it. All boolean tags are automatically returned, and not displayed.
- echo: when set to false, this option behaves exactly the same as the return option.
- is: when set to true, this option will force the tag to evaluate and return the tag value as a php boolean (see the PHP Manual-Boolean Type for conversion results.)
sidecart
- Overview
-
<?php shopp('cart','sidecart'); ?>
Displays the sidecart layout as defined in the sidecart.php template file.
NOTE: If you are using AJAX functionality with this tag, be sure to wrap the tag in a container that has a class of widget_shoppcartwidget. If your sidecart does not exist in a container with that class, the AJAX update handler will not be able to properly update the cart. When the sidecart is called as a WordPress Widget, the class is automatically added.
- Options
-
- return: when set to true, this option forces the tag to return the value instead of displaying the value to the page. This is useful when you need to write php logic that needs to evaluate the "value" of the tag, or to modify the value before displaying it. All boolean tags are automatically returned, and not displayed.
- echo: when set to false, this option behaves exactly the same as the return option.
- is: when set to true, this option will force the tag to evaluate and return the tag value as a php boolean (see the PHP Manual-Boolean Type for conversion results.)
- Examples
<div class="widget_shoppcartwidget"> <?php shopp('cart','sidecart'); ?> </div>
function
- Overview
-
<?php shopp('cart','function'); ?>
Includes hidden functional elements needed to control how the cart is managed. This tag is required within the <form> tag of the cart.php template file.
- Options
-
- None
empty-button
- Overview
-
<?php shopp('cart','empty-button'); ?>
Renders a button that empties the shopper's cart completely. The button is an XHTML <input type="submit"> element. It is given the ID of 'empty-button'. You may specify your own additional classes and your own value label.
- Options
-
- class: Default is not set. Allows you to specify custom CSS classes to the button element.
- disabled: Default is not set. A flag value that when included and set to any value (including empty) will disable the button.
- value: Default is Empty Cart. Set to the text to be used as the text on the button.
- accesskey: Default is not set. Specify a character (a letter for example) to be used as the button's accesskey.
- title: Default is not set. Set the title attribute of the rendered button element.
- tabindex: Default is not set. Set to a number to set the tab order of the element. When not set, the element will automatically be assigned a tab order by the web browser.
- return: when set to true, this option forces the tag to return the value instead of displaying the value to the page. This is useful when you need to write php logic that needs to evaluate the "value" of the tag, or to modify the value before displaying it. All boolean tags are automatically returned, and not displayed.
- echo: when set to false, this option behaves exactly the same as the return option.
- is: when set to true, this option will force the tag to evaluate and return the tag value as a php boolean (see the PHP Manual-Boolean Type for conversion results.)
- Examples
<?php shopp('cart','empty-button','class=empty&value=Clear Your Cart'); ?>
update-button
- Overview
-
<?php shopp('cart','update-button'); ?>
Renders a button that when clicked will cause the shopping cart to recalculate all totals including prices, promotional discounts, shipping, and taxes. The button is an XHTML <input type="submit"> element. It is given the ID of 'update-button'. You may specify your own additional classes and your own value label.
- Options
-
- class: Default is not set. Allows you to specify custom CSS classes to the button element.
- disabled: Default is not set. A flag value that when included and set to any value (including empty) will disable the button.
- value: Default is Update Subtotal. Set to the text to be used as the text on the button.
- accesskey: Default is not set. Specify a character (a letter for example) to be used as the button's accesskey.
- title: Default is not set. Set the title attribute of the rendered button element.
- tabindex: Default is not set. Set to a number to set the tab order of the element. When not set, the element will automatically be assigned a tab order by the web browser.
- return: when set to true, this option forces the tag to return the value instead of displaying the value to the page. This is useful when you need to write php logic that needs to evaluate the "value" of the tag, or to modify the value before displaying it. All boolean tags are automatically returned, and not displayed.
- echo: when set to false, this option behaves exactly the same as the return option.
- is: when set to true, this option will force the tag to evaluate and return the tag value as a php boolean (see the PHP Manual-Boolean Type for conversion results.)
totalitems
- Overview
-
<?php shopp('cart','totalitems'); ?>
Displays the total number of unique items in the shopping cart. This is different from the total quantity of all the items in the shopping cart.
- Options
-
- return: when set to true, this option forces the tag to return the value instead of displaying the value to the page. This is useful when you need to write php logic that needs to evaluate the "value" of the tag, or to modify the value before displaying it. All boolean tags are automatically returned, and not displayed.
- echo: when set to false, this option behaves exactly the same as the return option.
- is: when set to true, this option will force the tag to evaluate and return the tag value as a php boolean (see the PHP Manual-Boolean Type for conversion results.)
hasitems
- Overview
-
<?php if(shopp('cart','hasitems')) { … } ?>
Provides a simple test mechanism to allow different template layouts to be shown depending on whether there are items in the cart or not. This tag returns a true or false value.
- Options
-
- None
- Examples
- List the names of items in the cart
<?php if(shopp('cart','hasitems')): ?> <ul> <?php while(shopp('cart','items')): ?> <li><?php shopp('cartitem','name'); ?></li> <?php endwhile; ?> </ul> <?php else: ?> <p>There are no items in the cart.</p> <?php endif; ?>
items
- Overview
-
<?php while(shopp('cart','items')) { … } ?>
Loops through the items in the cart to display information specific to a single item. This is a construct similar to "The Loop" in WordPress and operates in much the same manner. Item specific information inside of this loop, however, is accessed through shopp('cartitems') tags. The tag functions as an iterator, returning a true value for each call as it passes over each item in the cart, and then false when it runs out of items.
- Options
-
- None
- Examples
- List the names of items in the cart
<?php if(shopp('cart','hasitems')): ?> <ul> <?php while(shopp('cart','items')): ?> <li><?php shopp('cartitem','name'); ?></li> <?php endwhile; ?> </ul> <?php else: ?> <p>There are no items in the cart.</p> <?php endif; ?>
lastitem
- Overview
-
<?php $item = shopp('cart','lastitem','return=true'); ?>
This is a programmer's tag, which returns the last item object added to the cart. Because the return is an object (not a string), you can not echo this to your template. This value must be assigned to a variable, for use with additional programming logic. For Shopp 1.0.17 and prior: Calling this tag requires the return option to be true, see Options.
- Options
-
One of these options required for Shopp 1.0.17 and prior:
- return: when set to true, this option forces the tag to return the value instead of displaying the value to the page. This is useful when you need to write php logic that needs to evaluate the "value" of the tag, or to modify the value before displaying it. All boolean tags are automatically returned, and not displayed.
- echo: when set to false, this option behaves exactly the same as the return option.
- is: when set to true, this option will force the tag to evaluate and return the tag value as a php boolean (see the PHP Manual-Boolean Type for conversion results.)
totalpromos
- Overview
-
<?php shopp('cart','totalpromos'); ?>
Displays the total number of promotions currently applied to the shopping cart.
- Options
-
- return: when set to true, this option forces the tag to return the value instead of displaying the value to the page. This is useful when you need to write php logic that needs to evaluate the "value" of the tag, or to modify the value before displaying it. All boolean tags are automatically returned, and not displayed.
- echo: when set to false, this option behaves exactly the same as the return option.
- is: when set to true, this option will force the tag to evaluate and return the tag value as a php boolean (see the PHP Manual-Boolean Type for conversion results.)
haspromos
- Overview
-
<?php if(shopp('cart','haspromos')) { … } ?>
Provides a simple test mechanism to allow different template layouts to be shown depending on whether there are promotions applied to the current cart. This tag returns a true or false value.
- Options
-
- None
- Examples
- Display applied promotion names and discount amounts
<?php if(shopp('cart','haspromos')): ?> <ul> <?php while(shopp('cart','promos')): ?> <li><?php shopp('cart','promo-name'); ?> (<?php shopp('cart','promo-discount'); ?>)</li> <?php endwhile; ?> </ul> <?php else: ?> <p>No promos have been applied.</p> <?php endif; ?>
promos
- Overview
-
<?php while(shopp('cart','promos')) { … } ?>
Loops through the promotions applied to the cart to display information specific to each applied promotion. This is a construct similar to "The Loop" in WordPress and operates in much the same manner. The tag functions as an iterator, returning a true value for each call as it passes over each promotion applied to the cart, and then false when it runs out of promos.
- Options
-
- None
- Examples
- Display applied promotion names and discount amounts
<?php if(shopp('cart','haspromos')): ?> <ul> <?php while(shopp('cart','promos')): ?> <li><?php shopp('cart','promo-name'); ?> (<?php shopp('cart','promo-discount'); ?>)</li> <?php endwhile; ?> </ul> <?php else: ?> <p>No promos have been applied.</p> <?php endif; ?>
promo-name
- Overview
-
<?php shopp('cart','promo-name'); ?>
Displays the name of the promotion currently applied. Used within a shopp('cart','promos') loop.
- Options
-
- return: when set to true, this option forces the tag to return the value instead of displaying the value to the page. This is useful when you need to write php logic that needs to evaluate the "value" of the tag, or to modify the value before displaying it. All boolean tags are automatically returned, and not displayed.
- echo: when set to false, this option behaves exactly the same as the return option.
- is: when set to true, this option will force the tag to evaluate and return the tag value as a php boolean (see the PHP Manual-Boolean Type for conversion results.)
promo-discount
- Overview
-
<?php shopp('cart','promo-discount'); ?>
Shows the total discount for an applied promotion. Used within a shopp('cart','promos') loop.
- Options
-
- before: Allows you to specify a prefix before the discount amount.
- after: A suffix added after the discount amount
- label: Allows you to specify a label to follow after the discount amount but before the after suffix.
- return: when set to true, this option forces the tag to return the value instead of displaying the value to the page. This is useful when you need to write php logic that needs to evaluate the "value" of the tag, or to modify the value before displaying it. All boolean tags are automatically returned, and not displayed.
- echo: when set to false, this option behaves exactly the same as the return option.
- is: when set to true, this option will force the tag to evaluate and return the tag value as a php boolean (see the PHP Manual-Boolean Type for conversion results.)
promo-code
- Overview
-
<?php shopp('cart','promo-code'); ?>
Displays an empty text input box and a button to accept promotional codes and apply them to the cart.
- Options
-
- class: Default is not set. Allows you to specify custom CSS classes to the button element.
- disabled: Default is not set. A flag value that when included and set to any value (including empty) will disable the button.
- value: Default is Apply Promo Code. Set to the text to be used as the text on the button.
- accesskey: Default is not set. Specify a character (a letter for example) to be used as the button's accesskey.
- title: Default is not set. Set the title attribute of the rendered button element.
- tabindex: Default is not set. Set to a number to set the tab order of the element. When not set, the element will automatically be assigned a tab order by the web browser.
- return: when set to true, this option forces the tag to return the value instead of displaying the value to the page. This is useful when you need to write php logic that needs to evaluate the "value" of the tag, or to modify the value before displaying it. All boolean tags are automatically returned, and not displayed.
- echo: when set to false, this option behaves exactly the same as the return option.
- is: when set to true, this option will force the tag to evaluate and return the tag value as a php boolean (see the PHP Manual-Boolean Type for conversion results.)
- Examples
<?php shopp('cart','promo-code','class=promo-input&value=Apply Promo Code'); ?>
promos-available
- Overview
-
<?php if(shopp('cart','promos-available')) {…} ?>
Used to test whether the promotions limit has been reached (when a promotions limit has been set.) This tag will return false when no additional promotions can be applied to the order.
- Options
-
- None
needs-shipping-estimates
- Overview
-
<?php if(shopp('cart','needs-shipping-estimates')) { … } ?>
Used to test whether shipping estimates are needed based on your current cart (has physical products that need shipped) and shipping settings (whether shipping cost will vary). This tag returns a true or false value. This is useful for detecting whether you need to gather information for generating a shipping estimate on the cart, and also for determining whether you need to display a estimate that has been calculated. See shipping-estimates below.
- Options
-
- None
- Examples
- Show shipping estimate controls if shipping is needed
<?php if (shopp('cart','needs-shipping-estimates')): ?> <small>Estimate shipping & taxes for:</small> <?php shopp('cart','shipping-estimates'); ?> <?php endif; ?>
shipping-estimates
- Overview
-
<?php shopp('cart','shipping-estimates'); ?>
Displays a drop-down menu that provides a list of countries for shipping destinations. This menu allows the shopper to select a shipping destination country to get a shipping quote without the need to fill out their entire shipping address. It should be noted that there is no submit button to go with the menu. JavaScript functionality is built-in to Shopp to detect when the menu is present and auto-update when the setting is changed. If the auto-update fails, the shopper can also use the button displayed by shopp('cart','update-button').
- Options
-
- return: when set to true, this option forces the tag to return the value instead of displaying the value to the page. This is useful when you need to write php logic that needs to evaluate the "value" of the tag, or to modify the value before displaying it. All boolean tags are automatically returned, and not displayed.
- echo: when set to false, this option behaves exactly the same as the return option.
- is: when set to true, this option will force the tag to evaluate and return the tag value as a php boolean (see the PHP Manual-Boolean Type for conversion results.)
needs-shipped
- Overview
-
<?php if(shopp('cart','needs-shipped')) { … } ?>
Used to test whether there are any physical goods in the cart that will need shipped to a physical address. This tag returns a true or false value.
- Options
-
- None
- Examples
- Show shipping costs if shipped items exist
<?php if(shopp('cart','needs-shipped')): ?> <tr class="totals"> <th scope="row"><?php shopp('cart','shipping','label=Shipping'); ?></th> <td class="money"><?php shopp('cart','shipping'); ?></td> </tr> <?php endif; ?>
has-shipping-methods
- Overview
-
<?php if(shopp('cart','has-shipping-methods')) { … } ?>
When there is physical products to be shipped in the cart, this tag is used to determine if there is more than one shipping method estimate. This tag returns a true or false value.
- Options
-
- None
has-ship-costs
- Overview
-
<?php if(shopp('cart','has-ship-costs')) { … } ?>
Used to test if the cart has shipping costs associated with it. It is important to note that this is different than the needs-shipped test. A cart can still have items that need shipped, but have no shipping costs due to a free shipping promotion, for example. This tag returns a true or false value.
- Options
-
- None
- Examples
- Show shipping costs if they exist
<?php if(shopp('cart','has-ship-costs')): ?> <tr class="totals"> <th scope="row"><?php shopp('cart','shipping','label=Shipping'); ?></th> <td class="money"><?php shopp('cart','shipping'); ?></td> </tr> <?php endif; ?>
- Aliases
-
- hasshipcosts
<?php if(shopp('cart','hasshipcosts')) { … } ?>
subtotal
- Overview
-
<?php shopp('cart','subtotal'); ?>
Displays the subtotal amount of the cart in the store's default currency. The subtotal is the sum of all of the item totals in the cart where the item total is calculated by multiplying the item quantity by the item's unit price.
- Options
-
- return: when set to true, this option forces the tag to return the value instead of displaying the value to the page. This is useful when you need to write php logic that needs to evaluate the "value" of the tag, or to modify the value before displaying it. All boolean tags are automatically returned, and not displayed.
- echo: when set to false, this option behaves exactly the same as the return option.
- is: when set to true, this option will force the tag to evaluate and return the tag value as a php boolean (see the PHP Manual-Boolean Type for conversion results.)
hasdiscount
- Overview
-
<?php if(shopp('cart','hasdiscount')) { … } ?>
Used to test whether there are any discount applied to the shopping cart or not. This tag returns a true or false value.
- Options
-
- None
- Examples
- Shows markup for discounts
<?php if(shopp('cart','hasdiscount')): ?> <tr class="totals"> <th scope="row">Discount</th> <td class="money">-<?php shopp('cart','discount'); ?></td> </tr> <?php endif; ?>
This example is from the default cart.php template file that is included with Shopp. It shows extra markup for labeling and formatting the discount amount in a table only when a discount is applied to the order.
discount
- Overview
-
<?php shopp('cart','discount'); ?>
Displays the total discount amount currently applied to the cart in the store's default currency.
- Options
-
- return: when set to true, this option forces the tag to return the value instead of displaying the value to the page. This is useful when you need to write php logic that needs to evaluate the "value" of the tag, or to modify the value before displaying it. All boolean tags are automatically returned, and not displayed.
- echo: when set to false, this option behaves exactly the same as the return option.
- is: when set to true, this option will force the tag to evaluate and return the tag value as a php boolean (see the PHP Manual-Boolean Type for conversion results.)
shipping
- Overview
-
<?php shopp('cart','shipping'); ?>
Displays the cost of shipping of the cart in the store's default currency. The shipping cost varies according to a number of different settings including the selected shipping method, the shipping rates set by the merchant, and the items in the cart that need shipped.
- Options
-
- return: when set to true, this option forces the tag to return the value instead of displaying the value to the page. This is useful when you need to write php logic that needs to evaluate the "value" of the tag, or to modify the value before displaying it. All boolean tags are automatically returned, and not displayed.
- echo: when set to false, this option behaves exactly the same as the return option.
- is: when set to true, this option will force the tag to evaluate and return the tag value as a php boolean (see the PHP Manual-Boolean Type for conversion results.)
hastaxes
- Overview
-
<?php if(shopp('cart','hastaxes')) { … } ?>
Used to test whether there are taxes calculated for the order. This tag returns a true or false value.
- Options
-
- None
tax
- Overview
-
<?php shopp('cart','tax'); ?>
Displays the total tax assessed for the cart in the store's default currency. Tax typically cannot be calculated until shipping destination is selected. As a result, tax amounts are only shown in the cart when the shipping destination has a tax rate associated with it.
- Options
-
- return: when set to true, this option forces the tag to return the value instead of displaying the value to the page. This is useful when you need to write php logic that needs to evaluate the "value" of the tag, or to modify the value before displaying it. All boolean tags are automatically returned, and not displayed.
- echo: when set to false, this option behaves exactly the same as the return option.
- is: when set to true, this option will force the tag to evaluate and return the tag value as a php boolean (see the PHP Manual-Boolean Type for conversion results.)
total
- Overview
-
<?php shopp('cart','total'); ?>
Displays the grand total amount for the cart in the store's default currency. The total is calculated as the sum of the cart's subtotal, discount (a negative value), shipping and tax.
- Options
-
- return: when set to true, this option forces the tag to return the value instead of displaying the value to the page. This is useful when you need to write php logic that needs to evaluate the "value" of the tag, or to modify the value before displaying it. All boolean tags are automatically returned, and not displayed.
- echo: when set to false, this option behaves exactly the same as the return option.
- is: when set to true, this option will force the tag to evaluate and return the tag value as a php boolean (see the PHP Manual-Boolean Type for conversion results.)
