WordPress教程:WooCommerce当免费送货可用时隐藏所有其他运送方式

经过 小朱笔记 | 3 月 17, 2019 | WordPress技巧 | 2 评论

当免费送货可用时隐藏所有其他运送方式

https:// Hide ALL shipping options when free shipping is available
add_filter( 'woocommerce_available_shipping_methods', 'hide_all_shipping_when_free_is_available' , 10, 1 );
 
/**
* Hide ALL Shipping option when free shipping is available
*
* @param array $available_methods
*/
function hide_all_shipping_when_free_is_available( $available_methods ) {
 
    if( isset( $available_methods['free_shipping'] ) ) :
 
    https:// Get Free Shipping array into a new array
    $freeshipping = array();
    $freeshipping = $available_methods['free_shipping'];
 
    https:// Empty the $available_methods array
    unset( $available_methods );
 
    https:// Add Free Shipping back into $avaialble_methods
    $available_methods = array();
    $available_methods[] = $freeshipping;
 
  endif;
 
  return $available_methods;
}

在哪里添加此代码?

将PHP代码放在主题或子主题functions.php文件的底部。

2 评论

  1. 请问是加在哪个文件里?

    Reply
    • 放在主题或子主题 functions.php文件底部

      Reply

提交评论

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理