• DONATE to NULLED!
    Вы можете помочь Форуму и команде, поддержать финансово.
    starwanderer - модератор этого раздела будет Вам благодарен!

Помощь Заказ в 1 клик WooCommerce без popup

mutter

Постоялец
Регистрация
23 Ноя 2015
Сообщения
68
Реакции
54
Добрый день! Подскажите как реализовать заказ в 1 клик WooCommerce без popup (форма на странице карточки товара)
99646

Все решения которые находил иду во всплывающих окнах, а нужно что бы сразу на самой странице товара и заказ падал в заказы самого WooCommerce.
1) WordPress версия актуальная
2) WooCommerce версия актуальная
3) Шаблон кастомный.
Может что подскажет как правильно написать решение или может есть готовое.
 

Вложения

  • Screenshot_1.png
    Screenshot_1.png
    10,6 KB · Просмотры: 106
Сделал сам
Форма:
PHP:
$idproduct = $product->get_id();
PHP:
<form class="form" id="ajax-contact-form" action="#">
<input placeholder="<?php _e('My phone', 'telform');?>"  id="tel" type="text" name="tel" >
<input  type="hidden" name="idproduct" id="idproduct" value="<?php echo $idproduct; ?>" >
<input type="submit" id="submit_tel" value="<?php _e('Call me!', 'telform');?>" class="btn " >
</form>
<div class="form-mess">
<div class="form-mess-ok" style="display:none"><?php _e('Your order is accepted', 'telform');?></div>
<div class="form-mess-error" style="display:none"><?php _e('An error has occurred', 'telform');?></div>
</div>
JS:

PHP:
jQuery(function($){
    $('#submit_tel').click(function(event){
        event.preventDefault();
        $(".form-mess-error").attr("style","display:none");
    $(".form-mess-ok").attr("style","display:none");
         var tel = $("#tel").val();
         var idproduct = $("#idproduct").val();
       
        var data = {
            'action': 'telsend',
            'tel': tel,
            'idproduct': idproduct
        };
        $.ajax({
            url:ajaxurl,
            data:data,
            type:'POST',
            success:function(res){
                count = res;
                if (count < 2){
                    $(".form-mess-ok").attr("style","display:block");
                    $(".form-mess-error").attr("style","display:none");
                     $("#tel").val('');
                 } else {
                      $(".form-mess-error").attr("style","display:block");
                    $(".form-mess-ok").attr("style","display:none");
                 }
            }
           
        });
    });

});
Functions:
PHP:
add_action('wp_ajax_telsend', 'telsend');
add_action('wp_ajax_nopriv_telsend', 'telsend');
function telsend()
{
$response = '';
$tel = $_POST['tel'];   

$idproduct = $_POST['idproduct'];
if($tel!=""){
           $address = array(
     'first_name' => $tel,
     'last_name' => '',
     'company' => '',
     'email'  => '',
     'phone'  => $tel,
     'address_1' => '',
     'address_2' => '',
     'city'  => '',
     'state'  => '',
     'postcode' => '',
     'country' => ''
    );

    $orderz = wc_create_order();
$id = $idproduct;
     $orderz->add_product(get_product($id), 1);
    $orderz->set_address($address, 'billing');
    $orderz->calculate_totals();
    $orderz->update_status('processing', $payment);
     $response = 1;
     } else {
         $response = 2;
     }

      echo $response;
      die();
}
 
Назад
Сверху