Stripe信用卡不使用WooCommerce模式结帐

发布于 2025-02-13 14:02:36 字数 2880 浏览 1 评论 0原文

我想将Stripe Checkout用于模态而不是结帐页面,但是当[WooCommerce_Checkout]快捷代码移动到模态时,Stripe Checkout表单被禁用,并且它可以作为页面结帐。

这是下面的主要功能

add_action( 'wp_ajax_getCheckoutPageContent', 'getCheckoutPageContentCallBack' );
add_action( 'wp_ajax_nopriv_getCheckoutPageContent', 'getCheckoutPageContentCallBack' );

function getCheckoutPageContentCallBack() {
    $product_id        = absint( $_POST['product_id'] );
    $quantity          = absint( $_POST['quantity'] );
    $product_status    = get_post_status( $product_id );
    $passed_validation = apply_filters( 'woocommerce_add_to_cart_validation', true, $product_id, $quantity );

    if ( WC()->cart->add_to_cart( $product_id, $quantity ) ) {
        do_action( 'woocommerce_ajax_added_to_cart', $product_id );
        global $woocommerce;
        $items = $woocommerce->cart->get_cart();

        wc_setcookie( 'woocommerce_items_in_cart', count( $items ) );
        wc_setcookie( 'woocommerce_cart_hash', md5( json_encode( $items ) ) );
        do_action( 'woocommerce_set_cart_cookies', true );

        define( 'WOOCOMMERCE_CHECKOUT', true );
        echo do_shortcode('[woocommerce_checkout]');

    }else{
        define( 'WOOCOMMERCE_CHECKOUT', true );
        echo do_shortcode('[woocommerce_checkout]');
    }
    die();
}

,下面的模式下面的

<!-- Start Booking Popup Modal Area -->
<div class="booking-popup-modal-area modal right fade" id="Booking-Popup-Modal" tabindex="-1" role="dialog" aria-labelledby="Booking-Popup-Modal" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <button type="button" class="btn-close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <div class="modal-body">
                <div id="checkOutPageContent">

                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    function customCheckout(event){
        var wp_ajax_url="<?php echo site_url();?>/wp-admin/admin-ajax.php";
        var data = {
            action: 'getCheckoutPageContent',
            product_id: jQuery(event.target).data('productid'),
            quantity: 1
        };

        jQuery.post( wp_ajax_url, data, function(content) {
            jQuery("#checkOutPageContent").html(content);
            jQuery("#Booking-Popup-Modal").modal('show');

        });
    }

</script>
<!-- End Booking Popup Modal Area -->

完整问题您可以在下面的屏幕截图

”在网络上找到任何合适的解决方案。

我现在该怎么办?

我在那里想念什么?

谢谢

I want to use the Stripe checkout into a modal instead of a checkout page but when the [woocommerce_checkout] shortcode move to the modal the Stripe checkout form gets disabled and it's completely working as page checkout.

Here is the main function like below

add_action( 'wp_ajax_getCheckoutPageContent', 'getCheckoutPageContentCallBack' );
add_action( 'wp_ajax_nopriv_getCheckoutPageContent', 'getCheckoutPageContentCallBack' );

function getCheckoutPageContentCallBack() {
    $product_id        = absint( $_POST['product_id'] );
    $quantity          = absint( $_POST['quantity'] );
    $product_status    = get_post_status( $product_id );
    $passed_validation = apply_filters( 'woocommerce_add_to_cart_validation', true, $product_id, $quantity );

    if ( WC()->cart->add_to_cart( $product_id, $quantity ) ) {
        do_action( 'woocommerce_ajax_added_to_cart', $product_id );
        global $woocommerce;
        $items = $woocommerce->cart->get_cart();

        wc_setcookie( 'woocommerce_items_in_cart', count( $items ) );
        wc_setcookie( 'woocommerce_cart_hash', md5( json_encode( $items ) ) );
        do_action( 'woocommerce_set_cart_cookies', true );

        define( 'WOOCOMMERCE_CHECKOUT', true );
        echo do_shortcode('[woocommerce_checkout]');

    }else{
        define( 'WOOCOMMERCE_CHECKOUT', true );
        echo do_shortcode('[woocommerce_checkout]');
    }
    die();
}

And the modal below

<!-- Start Booking Popup Modal Area -->
<div class="booking-popup-modal-area modal right fade" id="Booking-Popup-Modal" tabindex="-1" role="dialog" aria-labelledby="Booking-Popup-Modal" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <button type="button" class="btn-close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
            <div class="modal-body">
                <div id="checkOutPageContent">

                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    function customCheckout(event){
        var wp_ajax_url="<?php echo site_url();?>/wp-admin/admin-ajax.php";
        var data = {
            action: 'getCheckoutPageContent',
            product_id: jQuery(event.target).data('productid'),
            quantity: 1
        };

        jQuery.post( wp_ajax_url, data, function(content) {
            jQuery("#checkOutPageContent").html(content);
            jQuery("#Booking-Popup-Modal").modal('show');

        });
    }

</script>
<!-- End Booking Popup Modal Area -->

The complete issue you can see in the below screenshot

enter image description here

I can't understand anything and didn't find any suitable solution on the web.

What should I do now, please?

What I am missing there?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文