Отображение «Пожалуйста, выберите параметры продукта…» на странице оформления заказа после нажатия кнопки пользовательской проверки - PullRequest
0 голосов
/ 01 октября 2018

Я создал пользовательскую кнопку оформления заказа на странице одного товара.Он работает нормально. Но после выбора варианта с кнопкой проверки он перенаправляет на страницу оформления заказа с этой ошибкой 'Please choose product options…'.

Это мой код

function add_content_after_addtocart() {
     global $woocommerce;
    // get the current post/product ID
    $current_product_id = get_the_ID();

    // get the product based on the ID
    $product = wc_get_product( $current_product_id );

    // get the "Checkout Page" URL
    $checkout_url = WC()->cart->get_checkout_url();


    // run only on simple products 
    if( $product->is_type( 'variable' ) ){

        ?>
        <script>
    jQuery(function($) {
    <?php /* if our custom button is clicked, append the string "&quantity=", and also the quantitiy number to the URL */ ?>

        // if our custom button is clicked
        $(".custom-checkout-btn").on("click", function() {

            // get the value of the "href" attribute 
            $(this).attr("href", function() {
                // return the "href" value + the string "&quantity=" + the current selected quantity number
                return this.href + '&quantity=' + $('input.qty').val();
            });

        });
    });
    </script>
        <?php
        echo '<div class="col-sm-6"><div class="buy_now"><a href="'.$checkout_url.'?add-to-cart='.$current_product_id.'" class="single_add_to_cart_button buy_now_button button alt disabled custom-checkout-btn ajax_add_to_cart" >Buy Now</a></div></div><div class="clearfix"></div>';
?>

<?php
    }
    else if( $product->is_type( 'simple' ) ){

       echo '</div><div class="col-sm-6"><div class="p-t-35"></div><div class="buy_now"><a href="'.$checkout_url.'?add-to-cart='.$current_product_id.'" class="single_add_to_cart_button button alt buy_now_button button alt">Buy Now</a></div></div><div class="clearfix"></div>';
    }
}
add_action( 'woocommerce_after_add_to_cart_button', 'add_content_after_addtocart' );

Пожалуйста, помогите мне ..

1 Ответ

0 голосов
/ 01 октября 2018

У меня была та же проблема, и я связался со службой поддержки WooThemes, и они сказали, что

"Мы ограничиваем количество изменений, которые мы показываем на переднем конце для скорости. Но иногда вам нужно больше, чем36 вариантов, поэтому мы предлагаем этот фильтр, чтобы переопределить это ограничение. "

Пожалуйста, добавьте этот код ниже в файл functions.php.

  function custom_wc_ajax_variation_threshold( $qty, $product ) 
    { 
    return 100;
     } 
    add_filter( 'woocommerce_ajax_variation_threshold', 'custom_wc_ajax_variation_threshold', 100, 2 );
...