Buy Buttons templates

One of the greats features of TheCartPress 1.1.8+ is to create custom templates for the “Buy Button“.

By default, TheCartPress, is distributed with two templates for “Buy Buttons” . One for the Simple products and the other one for the Grouped products. These templates are located in thecartpress/themes templates/ and are called tcp_buybutton-simple.php and tcp_buybutton-grouped.php.

Customise in Themes

Any “Theme Designer” can copy these files to its own themes and customise them. The templates are a set of HTML code and function calls. The first idea could be to change the HTML structure around the PHP code, but TheCartPress allows to go further.
This example has been constructed without using any css style, only adding texts and modifying the position of the elements.

In thecartpress/templates/tcp_buybutton_template.php a “Theme Designer” or “Plugin Developer” can find all the functions used to create the Buy Button functionalities. Copying some of this functions, changing the name, to the file functions.php of the theme, it’s possible to change the look and feel of the “Buy Button” completely.

TheCartPress will look for “Buy Button” templates in child themes, themes or in the themes compatibility folder of TheCartPress.

Only One Unit per product

For example, exist products that, you only want to sell one unit . For this type of products, you need to hide the units field and allow, only, to buy one unit. To hide the units text box, you only have to remove this line <?php tcp_the_add_to_cart_unit_field( $post_id ); ?>.

To allow to buy only one unit <input type=”hidden” name=”tcp_count[]” id=”tcp_count_<?php echo $product_id; ?>” value=”1″/>

But, If you want that some products show the unit text box and the rest of products to hide this field,  you only have to duplicate the buy button template and let one with the hidden field and the other using the function “tcp_the_add_to_cart_unit_field“. From the product editor you can choose one by one the different templates to use.

Since TheCartPress 1.2, developers could use a new parameter in the function “tcp_the_add_to_cart_unit_field” to set this field hidden or visible.

Enjoy this awesome feature.