我不确定到底该怎么做,是的,我已经在网上到处找了.我确实找到了各种解决方案,但它们都不允许我有限的经验独自解决这个问题.

我需要的是:

"您刚刚在购物车中添加了数量产品名称.您的订单小计是小计.要 checkout 还是要继续购物?按钮|按钮"

因此,为了进一步解释它: "您刚刚在购物车中添加了3个蓝牙耳机.您的订单小计为299美元.您想 checkout 还是想继续购物?继续|转到 checkout "

换句话说,它应该计算添加了多少产品,并应该显示小计.在右侧,"继续"按钮链接到store 页面," checkout "按钮链接到" checkout "页面.

现在--这就是我的问题所在.. 在手机上时,总体布局有点混乱,所以我决定做一个相同的两个版本,允许文本和按钮以不同的方式对齐/放置.

这是我的代码,我肯定它来自其他地方--但我尽了最大努力修改它,尽我最大努力让它正常工作.

如果有人能帮帮我--谢谢!

add_filter( 'wc_add_to_cart_message_html', 'atcm_with_checkout_button_including_mobile_control', 10, 3 );
function atcm_with_checkout_button_including_mobile_control( $message, $qty, $count ) {

    $subtotal = wc_price(WC()->cart->subtotal);
    $count += $qty;
    
    $direct_to_shop = wc_get_shop_url();
    $direct_checkout = is_checkout() ? '#customer_details' : wc_get_checkout_url() . '#customer_details';

        if ( wp_is_mobile() && !is_checkout() ) {

        return sprintf (__( '
            <div style="font-size:20px">You just placed QTY of PRODUCT NAME in your cart.
            Your order total right now is %s. Wanna continue shopping %s or do you want to checkout %s? 
            </div>
        ' ), 
        
        $count, $subtotal, 

        '<a style="width:100%; border-left:none; margin-bottom:10%;" 
        class="shopping button alt" href="' . $direct_to_shop . '">' . __(" Continue Shopping ") . '</a>' );

        '<a style="width:100%; border-left:none; margin-top:10%;" 
        class="checkout button alt" href="' . $direct_checkout . '">' . __(" Go to Checkout ") . '</a>' );
    
        } else {

            if ( ! wp_is_mobile() && ! is_checkout() ) {
            
                return sprintf(__('
            <div style="font-size:20px">Your just placed QTY of PRODUCT NAME in your cart, brining your order total to %s. 
            Wanna continue shopping%s or do you want to checkout?%s
            </div>
            '), 
            $count, $subtotal, 
            '<a class="shopping button alt" href="' . $direct_to_shop . '">' . __(" Continue Shopping ") . '</a>' );            
            '<a class="checkout button alt" href="' . $direct_checkout . '">' . __(" Go to Checkout ") . '</a>' );
        
        }
    }
}

我搜索并try 了不同的 Select ,试图自己学习和修改.我就是做不到这一点.

推荐答案

代码中有一些错误和错误,请使用以下重新访问的代码:

add_filter( 'wc_add_to_cart_message_html', 'atcm_with_checkout_button_including_mobile_control', 10, 3 );
function atcm_with_checkout_button_including_mobile_control( $message, $products, $show_qty ) {
    $subtotal     = WC()->cart->subtotal;
    $product_ids  = array_keys($products);
    $product      = wc_get_product( reset($product_ids) );
    $quantity     = $products[$product->get_id()];
    $shop_url     = esc_url( wc_get_page_permalink('shop') );
    $checkout_url = wc_get_checkout_url() . '#customer_details';
    $html_string  = '<a class="button" href="%s">%s</a>';
    $shop_btn     = sprintf( $html_string, $shop_url, __('Continue Shopping') );
    $checkout_btn = sprintf( $html_string, $checkout_url, __('Go to Checkout') );

    if (  ! is_checkout() ) {
        if ( wp_is_mobile() ) {
            $message = sprintf ( '<div style="font-size:20px">' . 
                __('You just placed %d &times; %s in your cart. Your order total right now is %s. %s %s') .
                '</div>', $quantity, $product->get_name(), wc_price($subtotal), $checkout_btn, $shop_btn
            );
        } else {
            $message = sprintf( '<div style="font-size:20px">' . 
                __('You just placed %d &times; %s in your cart, %s %s <br>bringing your order total to %s.') .
                '</div>', $quantity, $product->get_name(), $checkout_btn, $shop_btn, wc_price($subtotal)
            );
        }
    }
    return $message;
}

代码位于您的子主题的unctions.php文件中(或在插件中).经过测试,效果良好.

enter image description here

Php相关问答推荐

从WooCommerce邮箱通知中的订单详细信息中删除产品列表

如何隐藏x轴图表上的值

致命错误:无法使用简单的php博客重新声明spl_autoload_Register()

PHP:PHP手册-Manual

Laravel eloquent-如果没有包含InitialValue的结果,则查询where Second Value

Php解压缩deflate64

在冲突和几何上插入的Postgres参数化查询在PHP中不起作用

如何配置我的.env文件以在laravel的一个项目中连接两个不同的数据库?

Laravel 10中的Validator类

强制客户在注册时 Select WooCommerce角色

在WooCommerce循环中添加子类别和产品之间的分隔符

在 WooCommerce 更新结帐事件上动态更新自定义内容

关于Laravel缓存出现的错误

订单完成后创建 WooCommerce 促销代码

如何将文件上传添加到 WooCommerce 结帐?

为WooCommerce中的运输方式ID设置必填的 checkout 订单备注字段

是否有适用于 Windows 的真正 64 位版本的 PHP 5.6?

Laravel Websockets 错误:(WebSocket 在建立连接之前关闭)

如何将在同一台服务器上运行的 2 个 PHP 应用程序与使用公共会话分开

将加密/解密函数从 PHP 转换为 NodeJS