Permalink
Join GitHub today
May 15, 2019 A step-by-step guide to creating a simple PHP shopping cart using SESSION and MySQL. Database and listed with the Add to Cart. And download the source code.
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upBranch:master
Find file Copy path
rodrigoprimoFix PEAR.Functions.FunctionCallSignature violations7337ab6Dec 20, 2019
10 contributors
<?php |
/** |
* Simple product add to cart |
* |
* This template can be overridden by copying it to yourtheme/woocommerce/single-product/add-to-cart/simple.php. |
* |
* HOWEVER, on occasion WooCommerce will need to update template files and you |
* (the theme developer) will need to copy the new files to your theme to |
* maintain compatibility. We try to do this as little as possible, but it does |
* happen. When this occurs the version of the template file will be bumped and |
* the readme will list any important changes. |
* |
* @see https://docs.woocommerce.com/document/template-structure/ |
* @package WooCommerce/Templates |
* @version 3.4.0 |
*/ |
defined( 'ABSPATH' ) || exit; |
global$product; |
if ( ! $product->is_purchasable() ) { |
return; |
} |
echowc_get_stock_html( $product ); // WPCS: XSS ok. |
if ( $product->is_in_stock() ) : ?> |
<?phpdo_action( 'woocommerce_before_add_to_cart_form' ); ?> |
<formclass='cart' action='<?phpechoesc_url( apply_filters( 'woocommerce_add_to_cart_form_action', $product->get_permalink() ) ); ?>' method='post' enctype='multipart/form-data'> |
<?phpdo_action( 'woocommerce_before_add_to_cart_button' ); ?> |
<?php |
do_action( 'woocommerce_before_add_to_cart_quantity' ); |
woocommerce_quantity_input( |
array( |
'min_value' => apply_filters( 'woocommerce_quantity_input_min', $product->get_min_purchase_quantity(), $product ), |
'max_value' => apply_filters( 'woocommerce_quantity_input_max', $product->get_max_purchase_quantity(), $product ), |
'input_value' => isset( $_POST['quantity'] ) ? wc_stock_amount( wp_unslash( $_POST['quantity'] ) ) : $product->get_min_purchase_quantity(), // WPCS: CSRF ok, input var ok. |
) |
); |
do_action( 'woocommerce_after_add_to_cart_quantity' ); |
?> |
<buttontype='submit' name='add-to-cart' value='<?phpechoesc_attr( $product->get_id() ); ?>' class='single_add_to_cart_button button alt'><?phpechoesc_html( $product->single_add_to_cart_text() ); ?></button> |
<?phpdo_action( 'woocommerce_after_add_to_cart_button' ); ?> |
</form> |
<?phpdo_action( 'woocommerce_after_add_to_cart_form' ); ?> |
<?phpendif; ?> |
Copy lines Copy permalink
When you do not need an X-Cart based product catalog
If you already have a website with a gallery of products being demonstrated to your visitors, you might want to rather not use X-Cart's ability to generate a Product catalog with Product pages. Instead, you may want to just insert the Add to cart and Checkout buttons into your existing pages.
Types of 'Add to cart' buttons
There are three types of 'Add to cart' buttons available:
- Text link
- A textual Add to cart hyperlink, which allows adding one item of a product to the shopping cart.
- Simple push button
- A graphic Add to cart hyperlink, which, like the textual link allows adding one item of a product to the shopping cart.
- Advanced push button
- An advanced Add to cart box, which displays the product price and allows setting additional options like making the purchase a gift, specifying a desired product quantity and adding the purchase to the shopping cart.
Inserting 'Add to cart' buttons into your website pages
X-Cart can generate the HTML code for the 'Add to cart' button that you can embed into your HTML pages.
To get HTML for an 'Add to cart' button:
- Login to the Admin area of your X-Cart store.
- Select Catalog -> Search for products on the menu.
- Find the product to generate the 'Add to cart' button for.
- On the 'Search results' page, select the product to generate the 'Add to cart' buttons for.
- Click the Generate HTML links button at the bottom of the 'Search results' page.
Clicking the Generate HTML links button brings up a set of generated HTML links for the selected product. Copy the HTML code for the desired link and paste that code to your web page.
You can also create links to product thumbnails or advanced HTML links with editable quantity and product options. Read on to the section Generating HTML links for products for more information.
Inserting the 'Checkout' button
To add a Checkout button to your site, copy the following HTML code and paste it to your web page:
Note: Make sure to replace the {xcart_http_location} with the real location of your X-Cart suite on the Web.
How To Code In Php
See also
Add To Cart Code In Php Free Download Template
Retrieved from 'https://help.x-cart.com/index.php?title=X-Cart:Adding_X-Cart%27s_%27Add_to_cart%27_and_%27Checkout%27_buttons_to_your_existing_(external)_product_catalog&oldid=11122'