首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Woocommerce -在使用UPS扩展时为单个项目创建免费送货服务

Woocommerce -在使用UPS扩展时为单个项目创建免费送货服务
EN

Stack Overflow用户
提问于 2013-03-17 11:05:42
回答 4查看 2.1K关注 0票数 1

我正在使用woocommerce中的UPS扩展。我需要提供一些项目的免费送货,绕过UPS计算器。这样做的一个好方法似乎是将商品标记为"virtuaL“,但这样商品就不需要送货了。我需要为这个项目要求发货。我已经能够自定义结帐页面并强制在虚拟项目上显示发货字段,但它们不会存储在实际订单中。

有人知道如何创建自定义函数或修改woocommerce文件以强制结帐过程要求在虚拟物品上送货,同时绕过UPS计算器吗?(发货时需要计算其他项目)

EN

回答 4

Stack Overflow用户

发布于 2013-03-31 23:24:23

我也遇到了同样的问题,插件的作者回复我说,这是不可能的,必须编写代码才能做到。

票数 1
EN

Stack Overflow用户

发布于 2014-06-13 03:58:56

我刚刚遇到了这个问题,也许这会对某人有所帮助。对于我想要免费送货的所有产品,我制作了虚拟产品。

然后我转到Woocommerce > Shipping Options选项卡,选中"Shipping Destination部分“中显示的”即使不需要也要收集送货地址“的复选框。

票数 0
EN

Stack Overflow用户

发布于 2015-12-15 07:39:41

我也需要这样,并且有一个可行的解决方案:

首先进入"Appearance"->"Editor"->"Theme Functions"中的functions.php,并添加以下代码(我强烈建议首先使用"child theme“,这样就不会修改主题的functions.php...or,也可以使用create a custom plugin)。

代码语言:javascript
运行
复制
/* Puts items with "free-shipping" shipping class into a different shipping package. */

    function free_woocommerce_cart_shipping_packages( $packages ) {

        // Reset the packages
        $packages = array();

        // Free items
        $freeshipping_items = array();
        $regular_items      = array();

        // Sort free from regular (replace "free-shipping" below with the shipping class slug you actually use).
        foreach( WC()->cart->get_cart() as $item ) {
            if( $item['data']->needs_shipping() ) {
                if( $item['data']->get_shipping_class() == 'free-shipping' ) {
                    $freeshipping_items[] = $item;
                }
                else {
                    $regular_items[] = $item;
                }
            }
        }

        // Put inside packages:
        if( $freeshipping_items ) {
            $packages[] = array(
                'ship_via'        => array( 'flat_rate' ),
                'contents'        => $freeshipping_items,
                'contents_cost'   => array_sum(wp_list_pluck($freeshipping_items, 'line_total')),
                'applied_coupons' => WC()->cart->applied_coupons,
                'destination'     => array(
                    'country'   => WC()->customer->get_shipping_country(),
                    'state'     => WC()->customer->get_shipping_state(),
                    'postcode'  => WC()->customer->get_shipping_postcode(),
                    'city'      => WC()->customer->get_shipping_city(),
                    'address'   => WC()->customer->get_shipping_address(),
                    'address_2' => WC()->customer->get_shipping_address_2()
                )
            );
        }
        if( $regular_items ) {
            $packages[] = array(
             // 'ship_via'        => array( 'usps' ),
                'contents'        => $regular_items,
                'contents_cost'   => array_sum(wp_list_pluck($regular_items, 'line_total')),
                'applied_coupons' => WC()->cart->applied_coupons,
                'destination'     => array(
                    'country'   => WC()->customer->get_shipping_country(),
                    'state'     => WC()->customer->get_shipping_state(),
                    'postcode'  => WC()->customer->get_shipping_postcode(),
                    'city'      => WC()->customer->get_shipping_city(),
                    'address'   => WC()->customer->get_shipping_address(),
                    'address_2' => WC()->customer->get_shipping_address_2()
                )
            );
        }

        return $packages;
    }

    add_filter('woocommerce_cart_shipping_packages', 'free_woocommerce_cart_shipping_packages');

其次,进入"Products"->"Shipping Classes"并创建一个名为"Free Shipping“的Shipping类,其中包含一个名为"free-shipping”的插件(该插件名称是我们将自定义函数绑定到的)。然后是"Add New Shipping Class“。

然后在您的"WooCommerce"->"Settings"->"Shipping"->"Flat Rate"中启用"Flat Rate“运输,并在"Shipping Class Costs”部分下,将"0.00“值放在我们刚刚创建的"Free Shipping”类旁边。在我的例子中,我还将"Calculation Type“设置为"Per Class”。然后是"Save changes“。

最后,在"WooCommerce"->"Settings"->"Shipping"->"Shipping Options"的"Shipping Methods“部分,确保"Flat Rate”的"Selection Priority“(在该名称的列中)高于您正在使用的任何其他送货方式,并且它是列表中的最后一种方式(您可以使用每个选项左侧的菜单图标进行拖动以重新排序)。"Save Changes“。

然后编辑您希望免费送货的产品之一,转到"Product Data"->"Shipping“部分,并将送货类别更改为"Free Shipping”(您创建的新类别)。然后"Update“该产品以保存更改。然后将它添加到您的购物车中,并将一些其他项目添加到您的购物车中,定期非免费送货。

测试。

现在,您应该会看到,免费送货商品有自己的送货"package“行("Shipping #1”和"Shipping #2"),即使购物车中每种商品都有一些,也是与仍应收取送货费用的商品分开的。

或者,您也可以尝试名为"Per Product Shipping“的全额付费插件。

或者这个free plugin may work也是如此(没有承诺)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15457059

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档