- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我试图隐藏除基于运输类别的一种运输方式之外的所有运输方式,实质上是在选择属于特定类别的产品时强制使用 FedEx 隔夜运输方式。
我从 this code 开始, 并按如下所示修改它:
add_filter( 'woocommerce_available_shipping_methods', 'hide_shipping_based_on_class' , 10, 1 );
function check_cart_for_share() {
// load the contents of the cart into an array.
global $woocommerce;
$cart = $woocommerce->cart->cart_contents;
$found = false;
// loop through the array looking for the tag you set. Switch to true if the tag is found.
foreach ($cart as $array_item) {
$term_list = wp_get_post_terms( $array_item['product_id'], 'product_shipping_class', array( "fields" => "names" ) );
if (in_array("Frozen",$term_list)) {
$found = true;
break;
}
}
return $found;
}
function hide_shipping_based_on_class( $available_methods ) {
// use the function above to check the cart for the tag.
if ( check_cart_for_share() ) {
// remove the rate you want
unset( $available_methods['canada_post,purolator,fedex:FEDEX_GROUND,fedex:GOUND_HOME_DELIVERY'] );
}
// return the available methods without the one you unset.
return $available_methods;
}
虽然它似乎没有隐藏任何运输方式。不确定我错过了什么......
这是一个多站点安装,我正在加拿大方面测试 http://stjeans.harbourcitydevelopment.com
我正在运行 Table Rate 运输模块,以及 FedEx、Purolator 和 Canada Post 模块。
最佳答案
我遇到了同样的问题,修改您的代码很有帮助。一个问题是“woocommerce_available_shipping_methods”过滤器已从 WooCommerce 2.1 中弃用。所以你必须使用新的:“woocommerce_package_rates”。有 WooCommerce tutorial也用于类似的任务。
所以,我更改了过滤器钩子(Hook),当条件为真时,我迭代所有运输方式/费率,找到我想向客户显示的那个,从中创建新数组并返回这个数组(只有一个项目) .
我认为您的问题(除了已弃用的钩子(Hook)之外)主要是错误的 unset($available_methods[...]) 行。它不能那样工作。
这是我的代码:
add_filter( 'woocommerce_package_rates', 'hide_shipping_based_on_class' , 10, 2 );
function hide_shipping_based_on_class( $available_methods ) {
if ( check_cart_for_share() ) {
foreach($available_methods as $key=>$method) {
if( strpos($key,'YOUR_METHOD_KEY') !== FALSE ) {
$new_rates = array();
$new_rates[$key] = $method;
return $new_rates;
}
}
}
return $available_methods;
}
警告!我发现 woocommerce_package_rates Hook 不会每次都触发,但只有当您更改购物车中的商品或商品数量时才会触发。或者它看起来像我。也许这些可用费率以某种方式缓存在购物车内容中。
关于php - Woocommerce,根据运输类别隐藏运输方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23701467/
我有一个Rails应用程序,它的搜索系统取决于elasticsearch,我已经使用盆景插件将其推到heroku上,但是每当我尝试在我的应用程序上搜索内容时,都会在日志中给我这个错误。 2017-07
有什么方法可以禁用 Magento 中的购物卡/结账/送货选项吗? 我正在开发一个产品比较网站,其价格是从联属网站列出的。 我实际上并没有在我的网站上销售任何东西。 最佳答案 aDVo,如果禁用以下m
这是关于 iOS 设备蓝牙配件开发的指导请求。 公开可用的文档/讨论似乎有限;我认为这是由于 MFI NDA。 如果配件开发像一般的 iOS 开发一样易于访问,我没有找到我期望的 iOS 蓝牙配件的数
我有下一个问题: 我在名为的汽车的榻榻米中有一个水桶。 我在Elasticsearch中具有索引-名为测试 我映射了我的文档。 在 elasticsearch 配置中,我设置了: couchbase.
我遇到了 woocommerce 运输问题,这是我在购物车页面上遇到的错误。 Fatal error: Call to a member function get_label() on null in
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题? Update the question所以它是on-topic对于堆栈溢出。 9年前关闭。 Improve this que
您好,我正在使用 WooCommerce 为客户创建一个 wordpress 网站。该站点已完成,但客户希望能够从 shop_order 页面创建发货。我已经弄明白了大部分,问题是我对 UPS API
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 2 年前。 Improve this qu
用户从桶中选择 1 到 {N} 个产品 对于每个产品,供应商提供 {N} 个报价 我想给用户机会告诉他 我想要的输出: 如果您从供应商 (A) 处购买 5 件产品的总成本为 87 美元 如果您从供应商
FedEx 运输 API 是否具有 SOAP 端点?我找不到 WSDL 端点。 最佳答案 自从这里的其他 2 个答案以来,他们的网站已经更改。 最直接的答案是他们没有经典的 WSDL 端点,您只需在其
我正在将 Nodejs UPS 运输 API 与我的网站集成。我正在使用this模块。我使用了取货API。但它抛出错误 Missing or invalid AccountNumber UPS 。添加
我是一名优秀的程序员,十分优秀!