0

I need to create custom elementor product carousel. From that carousel there is a date field. User can select date and add product into cart. The selected date will be displayed as 'preferred date' into metadata. But unfortunately I can't save and display the date into product meta data here is the code

<div class="ark_item">
<div class="ark_single_item">
    <?php if (isset($settings['display_image']) && ($settings['display_image'] == 'yes')) { ?>
        <div class="ark_thumbnail">
            <a href="<?php echo esc_url(get_permalink($product->get_id())); ?>">
                <?php
                if ($thumbnail_id) {
                    $image_src = \Elementor\Group_Control_Image_Size::get_attachment_image_src($thumbnail_id, 'thumbnail_size', $settings);
                    echo sprintf('<img src="%s" title="%s" alt="%s"%s />', esc_attr($image_src), get_the_title($thumbnail_id), ark_get_attachment_alt($thumbnail_id), '');
                }
                ?>
            </a>
        </div>
    <?php } ?>
    <div class="ark_content">
        <div class="ark_title">
            <h2 style="text-align: <?php echo isset($settings['title_text_align']) ? esc_attr($settings['title_text_align']) : ''; ?>">
                <a href="<?php echo esc_url($product->get_permalink()); ?>"><?php echo esc_html($product->get_title()); ?></a>
            </h2>
        </div>
        <div class="ark_description">
            <?php if ($display_rating == 'yes') { ?>
                <div class="ark-rating">
                    <?php
                    if ('no' !== get_option('woocommerce_enable_review_rating')) {
                        $rating_count = $product->get_rating_count();
                        $review_count = $product->get_review_count();
                        $average = $product->get_average_rating();
                        $product_id = $product->get_id();
                    ?>
                        <div class="ark-rating-icons">
                            <?php echo ark_display_product_rating($average, $rating_count, $product_id); ?>
                        </div>
                    <?php } ?>
                </div>
            <?php } ?>
            <?php if ($display_price == 'yes') { ?>
                <div class="ark_price">
                    <?php echo $product->get_price_html(); ?>
                </div>
            <?php } ?>
            <div class="ark_date">
                <input type="date" name="selected_date" id="selected_date_<?php echo esc_attr($product->get_id()); ?>">
            </div>
            <div class="ark_quantity">
                <!-- Default Quantity Input -->
                <div class="quantity">
                    <?php
                    $input_args = apply_filters('woocommerce_quantity_input_args', array(
                        'input_id' => 'adult_quantity_' . esc_attr($product->get_id()),
                        'input_name' => 'adult_quantity',
                        'input_value' => isset($_POST['adult_quantity']) ? wc_stock_amount($_POST['adult_quantity']) : 1,
                        'classes' => apply_filters('woocommerce_quantity_input_classes', array('input-text', 'qty', 'text'), $product),
                        'max_value' => apply_filters('woocommerce_quantity_input_max', $product->get_max_purchase_quantity(), $product),
                        'min_value' => apply_filters('woocommerce_quantity_input_min', $product->get_min_purchase_quantity(), $product),
                        'step' => apply_filters('woocommerce_quantity_input_step', 1, $product),
                        'pattern' => apply_filters('woocommerce_quantity_input_pattern', has_filter('wc_stock_amount', 'wc_stock_amount') ? '[0-9]*' : ''),
                        'inputmode' => apply_filters('woocommerce_quantity_input_inputmode', has_filter('wc_stock_amount', 'wc_stock_amount') ? 'numeric' : ''),
                    ), $product);

                    woocommerce_quantity_input($input_args);
                    ?>
                </div>
            </div>
            <div class="ark_cartbtn">
                <div class="ark-add-to-cart">
                    <?php
                    // Default quantity is adult_quantity
                    $default_quantity = isset($_POST['adult_quantity']) ? wc_stock_amount($_POST['adult_quantity']) : 1;

                    // Add the product to the cart
                    $cart_item_key = WC()->cart->add_to_cart($product->get_id(), $default_quantity, 0, array(), array('selected_date' => $selected_date));

                    echo sprintf(
                        '<a href="%s" data-quantity="%s" class="%s" %s>%s</a>',
                        esc_url(wc_get_cart_url()),
                        esc_attr($default_quantity),
                        esc_attr(implode(' ', array_filter(array(
                            'button', 'product_type_' . $product->get_type(),
                            $product->is_purchasable() && $product->is_in_stock() ? 'add_to_cart_button' : '',
                            $product->supports('ajax_add_to_cart') ? 'ajax_add_to_cart' : '',
                            'ark_add_to_cart_btn'
                        )))),
                        wc_implode_html_attributes(array(
                            'data-product_id' => $product->get_id(),
                            'data-product_sku' => $product->get_sku(),
                            'aria-label' => $product->add_to_cart_description(),
                            'rel' => 'nofollow',
                        )),
                        esc_html($product->add_to_cart_text())
                    );
                    ?>
                </div>
            </div>
        </div>
    </div>
</div>

I can't add the selected date from here into woocommerce session at cart page .. your any help to be helpful for me...

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.