V
V
Vitaly Melnichuk2018-07-16 15:07:12
WordPress
Vitaly Melnichuk, 2018-07-16 15:07:12

How to fix the cart on Wordpress?

Hi all! There is a problem on the site adc.e-dev.pp.ua it is made on Wordpress and there is a Rent button. When you click on the button, we get into the basket prntscr.com/k70zh3 everything seems to be ok. I sent it from the catalog to the tag

<form action="<?php echo site_url() ?>/cart" method="post">

                                        <?php 
                                        session_start();

$_SESSION['count'] = $count;
$_SESSION['timedata'] = $timedata;
$_SESSION['title'] = $title;
$_SESSION['price'] = get_field('price', $post_id);
$_SESSION['thumb'] = $thumb;
$_SESSION['post_id'] = $post_id;

                                         ?>
                                        <input type="hidden" name="post_id" value="<?php the_ID(); ?>">
                                        <input type="hidden" name="title" value="<? the_title($post_id); ?>">
                                        <input type="hidden" name="price" value="<?php the_field('price', $post_id); ?>">
                                        <input type="hidden" name="thumb" value="<?php
$thumb_id = get_post_thumbnail_id();
$thumb_url = wp_get_attachment_image_src($thumb_id,'full', true);
echo $thumb_url[0];
?>">
****
</form>

And the cart page is already accepting. But the problem is that it's impossible to save it all in the session, and if I add one more product, then the block below is not added, but the current one disappears. How can I fix this? Lack of js and php skills. Plugins for an online store are not suitable.
<?php echo $_POST['title']; ?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2018-07-16
@webinar

You need to have an array, like items, which will already have titles, etc. for example

[
['id'=>'someid', 'title' => 'someTitle', ....],
['id'=>'someid2', 'title' => 'someTitle2', ....],
['id'=>'someid3', 'title' => 'someTitle3', ....],
]

And thrust this array into the session. Then you add and remove an array element, otherwise you just overwrite the title of course.
That is, for example, the output will be
$items = $_SESSION['items'];
echo 'количество: '. count($items);
foreach($items as $one){
echo $one['title'];
}

But it seems to me that it is better to store the basket in localStorage, and not in the session

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question