WooCommerce-免费送货时隐藏其他送货方式 - php

当Woocommerce提供免费送货服务时,我想隐藏其他送货方式。

因为最新版本的woocommerce现在仍显示其他送货选项,即使有免费送货选项也是如此。

请帮忙

参考方案

最近有WooCommerce 2.6+的代码片段。您可以使用:

add_filter( 'woocommerce_package_rates', 'hide_other_shipping_when_free_is_available', 100, 2 );

function hide_other_shipping_when_free_is_available( $rates, $package ) {

    $free = array();
    foreach ( $rates as $rate_id => $rate ) {
        if ( 'free_shipping' === $rate->method_id ) {
            $free[ $rate_id ] = $rate;
            break;
        }
    }
    return ! empty( $free ) ? $free : $rates;
}

您将需要刷新运送缓存的数据:在woocommerce运送设置中,禁用,保存和启用,保存当前运送区域的相关运送方法。

对于WooCommerce 2.5,您应该尝试以下操作:

add_filter( 'woocommerce_package_rates', 'hide_shipping_when_free_is_available', 10, 2 );

function hide_shipping_when_free_is_available( $rates, $package ) {

    // Only modify rates if free_shipping is present
    if ( isset( $rates['free_shipping'] ) ) {

        // To unset a single rate/method, do the following. This example unsets flat_rate shipping
        unset( $rates['flat_rate'] );

        // To unset all methods except for free_shipping, do the following
        $free_shipping          = $rates['free_shipping'];
        $rates                  = array();
        $rates['free_shipping'] = $free_shipping;
    }

    return $rates;
}

将此代码粘贴到活动子主题或主题中的function.php文件中。

参考:

Hide other shipping methods when FREE SHIPPING is available (official doc)
WooCommerce Free Shipping if over 5 pounds

Woocommerce:基于用户输入的自定义价格 - php

我不想在这里发布,但找不到所需的答案,我也没有足够的声誉来评论其他非常相似的问题,以获取确切答案。我从这篇文章中找到了一个几乎完美的答案:WooCommerce: Add product to cart with price override?使用代码:add_action( 'woocommerce_before_calculate_totals…

避免对woocommerce可变产品的版本选择进行图像更改 - php

在Woocommerce中,如何避免选择(可变产品)的变体时图像发生变化?任何帮助表示赞赏。 参考方案 如果您不需要为变体更改图片,则应从分配的变体中删除图像。我想它嵌入了插件或主题功能

如何显示用户的WooCommerce订阅详细信息? - php

我已经创建了一个自定义页面模板,并且想要显示用户订阅的特定详细信息(例如,订阅开始日期)。“我的帐户”页面上可用的挂钩显示了此内容,但我不知道如何拆除挂钩的输出,甚至不知道如何将其显示在页面模板上。任何帮助,将不胜感激! 参考方案 在活动主题的functions.php中添加以下代码。add_shortcode('wdm_my_subscripti…

如何在Woocommerce中的“添加到购物车”按钮上显示加载图标 - php

我想在用户单击添加到购物车按钮上时显示一个加载符号。当前在我的网站上,当用户单击按钮时,它在2-4秒内不执行任何操作并显示查看购物车按钮。我想在这4秒钟内显示一些加载或旋转图标。可能吗?有人可以指导我吗链接:http://www.myeatable.com/cnc-ongole/ php参考方案 对于添加到购物车上的加载图像,我可能建议在您的js中编写代码,…

woocommerce获取属性值列表 - php

我在wordpress上使用woocommerce创建了一个简单的购物网站,并为产品添加了一些属性。它们是size和color。在size之下,我有各种值,包括Small,Medium和Large。颜色相同,即。红色,蓝色,绿色。我想做的是在下拉列表中显示这些值。基本上只列出它们,这样我就可以将这些值用作商店目录页面的过滤器。任何帮助都会很棒。编辑:我研究了…