Woocommerce添加立即购买按钮的教程

您可以使用 WooCommerce 钩子woocommerce_after_add_to_cart_button。此钩子将在“添加到购物车”按钮之后添加内容。

如果客户单击此按钮,产品应添加到购物车,客户应被转到结帐页面。

在您的子主题中添加以下代码functions.php

/* Create Buy Now Button dynamically after Add To Cart button */
    function add_content_after_addtocart() {
    
        // 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( 'simple' ) ){
            echo 'Buy Now';
            //echo 'Buy Now';
        }
    }
    add_action( 'woocommerce_after_add_to_cart_button', 'add_content_after_addtocart' );

 

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

给TA打赏
共{{data.count}}人
人已打赏
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索