Add to cart php template

claudiosanches / add-to-cart.php

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters

Great loop! Saved me a ton of time, thanks.

Hello, thanks for the code, for some reason the quantity is not matching the input.

The only takes the first initial input, if I update the input to something else, it keeps adding the initial number. Any help?

Almost Perfect, only issue is i got another plugin for variable products which show option selection box, quantity selection box and of course an Add to cart Button as well, but color, size, position of add to cart button is not exactly like on single product page and under the variable product page , how could i fix that . have a look at screenshot here http://tinypic.com/r/a4o6t0/8

mrgarry05,
Could you share that plugin you mention?

This is generating errors on server running php5.4

( ! ) WARNING: ILLEGAL STRING OFFSET ‘CLASS’ IN /MEDIA/DATA/WWW/DEV-PALEOBOXMEALS/WP-CONTENT/THEMES/JUPITER/WOOCOMMERCE/CONTENT-PRODUCT.PHP ON LINE 219

It’s referencing this line:
echo sprintf(‘%s’, esc_attr( $product->id ), esc_attr( $product->get_sku() ), esc_attr( $link[‘class’] ), esc_html( $link[‘label’] ) );

Any Ideas? I have read that these offset errors are common on PHP 5.4 but not exactly sure how to fix it, any help would be appreciated!

I have used the above code and thank you for this. But i could not get the product variable option in the product single page, if the product type is «Variable Product». So i have changed two lines and it is working fine now.

switch ( $product->product_type ) case «variable» :
$link = apply_filters( ‘variable_add_to_cart_url’, get_permalink( $product->id ) );
$label = woocommerce_variable_add_to_cart();
break;

Not working on latest woocommerce (tested with storefront theme).

It worked verry fine but i upgrade woocommerce and it not working now 🙁
With latest woocommerce and storefront, it not work
Please help me if you can

Since 2.5.2 you have to add .ajax_add_to_cart css class to your link.
See here woocommerce/woocommerce@856d192

Yes, as ebelrose said. In your add_to_cart.php you must replace «product_type_simple» with «ajax_add_to_cart» and it works.
Thank you very much, it worked great for me. (btw im not sure this is the correct solution, but it works for me)

WooCommerce add-to-cart.js uses jQuery data() function, in order to avoid cache issues update the quantity attribute with the data() function.

Use this:
$( this ).parent( ‘.quantity’ ).next( ‘.add_to_cart_button’ ).data( ‘quantity’, $( this ).val() );

Instead of this
$( this ).parent( ‘.quantity’ ).next( ‘.add_to_cart_button’ ).attr( ‘data-quantity’, $( this ).val() );

I’m building a custom e-commerce website using woocommerce and I’m having some trouble fixing the «add to cart button». Whenever I add the multiple amounts it only increments or adds one item to the cart. This only happens when I create custom loop to query woocommerce products

On the shop and single-product page, it works fine. If I add 10 items and press the add to cart button. It exactly adds 10 items to the cart.

Here is the code I have been working on. I really don’t know why it only increments one item to the cart. I tried applying ebelrose, raczosala and MonteroJJ and still the same output

‘product’, ); $crate_products = new WP_Query($args); if ($crate_products->have_posts()): while ($crate_products->have_posts()): $crate_products->the_post(); ?>

Interested to know what you make of an alternative approach here. Also be interested to know if Ajax could be implemented in core WC?

So it does work just the add to cart filter for variable products have changed.

So if you do change the variable apply filter it will work.

So you can use this filter to remove the select options variable add to cart text.

// remove the filter
remove_filter( ‘variable_add_to_cart_text’, ‘filter_variable_add_to_cart_text’, 10, 3 );

Does anyone know how you can adapt this code so that the page does not refresh after adding the product to the cart? Is anyone else having the same problem?

Источник

How to Create a Simple Shopping Cart in PHP 2022

The Shopping Add to Cart Script is useful because it allows you to add multiple order products in a single transaction. You will also see here how powerful the functionality of the session.

What are the features of PHP Shopping Cart Source Code?

This PHP Shopping Cart Source Code contains the following features.

    • Product Listing
    • Adding of Products
    • Product Updating
    • PHP Cart Removing of item.

    In this PHP code for shopping cart system, it advised that you will use Twitter Bootstrap templates for you to have a beautiful design.

    PHP code for shopping cart system using Twitter Bootstrap Templates

    Let’s begin to write PHP Code for Shopping Cart System:

    1. Create a MySQL Database and name it “productdb”.

    Note: You can click here MySQL Database if you want to learn more about the database.

    2. Execute the query for “add to cart database table” in the MySQL database.

    CREATE TABLE IF NOT EXISTS `tblproduct` ( `PRODUCTID` int(11) NOT NULL AUTO_INCREMENT, `MODEL` varchar(30) NOT NULL, `BRAND` varchar(30) NOT NULL, `DESCRIPTION` varchar(99) NOT NULL, `PRICE` double NOT NULL, PRIMARY KEY (`PRODUCTID`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;

    3. Populate the add to cart database table by executing the query below.

    INSERT INTO `tblproduct` (`PRODUCTID`, `MODEL`, `BRAND`, `DESCRIPTION`, `PRICE`) VALUES (1, 'HK-LE3212UVP', 'Sharp', 'LCD VIDEO-KARAOKE 32''''', 33298), (2, 'HK-LE1110UVP', 'Sharp', 'LCD VIDEO-KARAOKE 19''''', 22198), (3, '21V-FS720S', 'Sharp', 'Pure Flat TV ', 7190), (4, 'ES-D708', 'Sharp', 'Spin Dryer 7kg ', 4998), (5, 'ES-D958', 'Sharp', 'Spin Dryer 9.5 KG', 5698), (6, 'SJ-DT55AS', 'Sharp', '5.4 CU.FT S/D SEMI AUTO ', 10900);

    4. Create a connection between the PHP script and MySQL Database. Name it “config.php”

    Note: You can follow the tutorial Connect PHP/MYSQL if you want to have another variation in connecting PHP/MySQL.

    $server = ‘localhost’; $dbuser = ‘root’; $dbpass = »; $dbname = ‘productdb’; $con = mysql_connect($server, $dbuser, $dbpass); if (isset($con)) < # code. $dbSelect = mysql_select_db($dbname); if (!$dbSelect) < echo "Problem in selecting database! Please contact administraator"; die(mysql_error()); >> else

    5. Create a PHP file called “index.php” for index PHP Cart.

    6. Do the following code for the cart list. Name it “cart.php.”

    7. Create a PHP file called “process.php” and add the following code for removing of adding and removing of an item in the cart.

    if (!empty($_SESSION[‘janobecart’])) < // count the session array varible $max = count($_SESSION['janobecart']); if (!isset($exist))

     /*    */ alert(‘Item is already in the cart.’) /**/ $_SESSION[‘janobecart’] = array(); $_SESSION[‘janobecart’][0][‘PRODUCTID’] = $pid; $_SESSION[‘janobecart’][0][‘PRICE’] = $price; $_SESSION[‘janobecart’][0][‘QUANTITY’] = 1; > ?>

    Note: The code below is a Pop-up Message Using Javascript. This pop-up message is used to display messages about the action of the user, whether successfully executed or not.

     /* */ alert('Item has been added in the cart.') /* */ unset($_SESSION['tot']); ?>
     /* */ alert('Item has been removed in the cart.') /* redirect to main page.*/ window.location='cart.php' $_SESSION['janobecart'] = array_values($_SESSION['janobecart']); > ?>

    Conclusion

    In this lesson, we learn how to make add to cart in PHP. Wherein, the output you have done here can be integrated later on to your website. I hope we can hear some feedback from you.

    Источник

    claudiosanches / add-to-cart.php

    This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters

    This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters

    Exactly what I needed, thank you!

    Actually i tried the above step by adding them to add-to-cart.php file but it didnt work. please help on this.

    Great stuff, works fine for me!

    but it dont affect my «single product» page.

    how can i make this snipet work in my single page?

    thanks for the code, works perfectly. but there is some issue
    Each time you add product it appends on previous quantity i needs it to update cart with latest quantity., also when u add 0 products it says 1 product added.

    Great loop! Saved me a ton of time, thanks.

    Hello, thanks for the code, for some reason the quantity is not matching the input.

    The only takes the first initial input, if I update the input to something else, it keeps adding the initial number. Any help?

    Almost Perfect, only issue is i got another plugin for variable products which show option selection box, quantity selection box and of course an Add to cart Button as well, but color, size, position of add to cart button is not exactly like on single product page and under the variable product page , how could i fix that . have a look at screenshot here http://tinypic.com/r/a4o6t0/8

    mrgarry05,
    Could you share that plugin you mention?

    This is generating errors on server running php5.4

    ( ! ) WARNING: ILLEGAL STRING OFFSET ‘CLASS’ IN /MEDIA/DATA/WWW/DEV-PALEOBOXMEALS/WP-CONTENT/THEMES/JUPITER/WOOCOMMERCE/CONTENT-PRODUCT.PHP ON LINE 219

    It’s referencing this line:
    echo sprintf(‘%s’, esc_attr( $product->id ), esc_attr( $product->get_sku() ), esc_attr( $link[‘class’] ), esc_html( $link[‘label’] ) );

    Any Ideas? I have read that these offset errors are common on PHP 5.4 but not exactly sure how to fix it, any help would be appreciated!

    I have used the above code and thank you for this. But i could not get the product variable option in the product single page, if the product type is «Variable Product». So i have changed two lines and it is working fine now.

    switch ( $product->product_type ) case «variable» :
    $link = apply_filters( ‘variable_add_to_cart_url’, get_permalink( $product->id ) );
    $label = woocommerce_variable_add_to_cart();
    break;

    Not working on latest woocommerce (tested with storefront theme).

    It worked verry fine but i upgrade woocommerce and it not working now 🙁
    With latest woocommerce and storefront, it not work
    Please help me if you can

    Since 2.5.2 you have to add .ajax_add_to_cart css class to your link.
    See here woocommerce/woocommerce@856d192

    Yes, as ebelrose said. In your add_to_cart.php you must replace «product_type_simple» with «ajax_add_to_cart» and it works.
    Thank you very much, it worked great for me. (btw im not sure this is the correct solution, but it works for me)

    WooCommerce add-to-cart.js uses jQuery data() function, in order to avoid cache issues update the quantity attribute with the data() function.

    Use this:
    $( this ).parent( ‘.quantity’ ).next( ‘.add_to_cart_button’ ).data( ‘quantity’, $( this ).val() );

    Instead of this
    $( this ).parent( ‘.quantity’ ).next( ‘.add_to_cart_button’ ).attr( ‘data-quantity’, $( this ).val() );

    I’m building a custom e-commerce website using woocommerce and I’m having some trouble fixing the «add to cart button». Whenever I add the multiple amounts it only increments or adds one item to the cart. This only happens when I create custom loop to query woocommerce products

    On the shop and single-product page, it works fine. If I add 10 items and press the add to cart button. It exactly adds 10 items to the cart.

    Here is the code I have been working on. I really don’t know why it only increments one item to the cart. I tried applying ebelrose, raczosala and MonteroJJ and still the same output

    ‘product’, ); $crate_products = new WP_Query($args); if ($crate_products->have_posts()): while ($crate_products->have_posts()): $crate_products->the_post(); ?>

    Interested to know what you make of an alternative approach here. Also be interested to know if Ajax could be implemented in core WC?

    So it does work just the add to cart filter for variable products have changed.

    So if you do change the variable apply filter it will work.

    So you can use this filter to remove the select options variable add to cart text.

    // remove the filter
    remove_filter( ‘variable_add_to_cart_text’, ‘filter_variable_add_to_cart_text’, 10, 3 );

    Does anyone know how you can adapt this code so that the page does not refresh after adding the product to the cart? Is anyone else having the same problem?

    Источник

    Читайте также:  Таблицы
Оцените статью