반응형
wocommerce_shipping_free_shipping_is_available이 작동하지 않습니다.
WoCommerce를 WordPress 설치에서 커스터마이징했습니다.
다음과 같은 것이 있습니다.
/**
* Disable free shipping for select products
*
* @param bool $is_available
*/
function my_free_shipping( $is_available ) {
global $woocommerce;
// set the product ids that are ineligible
$ineligible = array( '14009', '14031' );
// get cart contents
$cart_items = $woocommerce->cart->get_cart();
// loop through the items looking for one in the ineligible array
foreach ( $cart_items as $key => $item ) {
if( in_array( $item['product_id'], $ineligible ) ) {
return false;
}
}
// nothing found return the default value
return $is_available;
}
add_filter( 'woocommerce_shipping_free_shipping_is_available', 'my_free_shipping', 20 );
WordPress와 WooCommerce를 업데이트하면 "wocommerce_shipping_free_shipping_is_available" 필터가 트리거되지 않습니다.
뭐가 잘못됐나요?
필터가 더 이상 사용되지 않는다는 것을 발견했고 이제 필터를 사용해야 합니다.
더 이상 사용하지 않거나 설치에 문제가 있습니까?
갱신하다
마지막으로 저는 wocommerce_shipping_free_shipping_is_사용 가능 및 wocommerce_package_rate의 두 가지 후크를 사용하고 있습니다.
wocommerce_shipping_free_shipping_is_사용 가능한 후크는 사용하지 않는 것 같습니다.
이게 내 암호입니다.
add_filter('woocommerce_shipping_free_shipping_is_available', array( $this, 'enable_free_shipping'), 40, 1);
if ( version_compare( WOOCOMMERCE_VERSION, '2.1', '>' ) ){
add_filter('woocommerce_package_rates', array( $this, 'free_shipping_filter'), 10, 1);
}else{
add_filter('woocommerce_available_shipping_methods', array( $this, 'free_shipping_filter'), 10, 1);
}
function enable_free_shipping($is_available){
global $woocommerce;
if ( sizeof( $woocommerce->cart->get_cart() ) > 0 ) {
/* some check here to enable or not free shipping */
return $is_available;
}else{
return $is_available;
}
}
function free_shipping_filter( $available_methods )
{
foreach ($available_methods as $key => $method) {
if ($method->method_id == 'free_shipping'){
$available_methods = array();
$available_methods['free_shipping:1'] = $method;
break;
}
}
return $available_methods;
}
enable_free_
무료 배송 방법 활성화 여부
free_shipping_필터
무료 배송 방법만 표시(활성화된 경우)
후크가 잘 작동하지 않는 이유는 유효한 쿠폰에 대해서만 무료 배송 방법을 활성화해야 하기 때문입니다.이렇게 해서 일반 사용자들은 "무료 배송 방법"을 보지 못하지만, 저는 후크 woocmerce_shipping_free_shipping_is_를 통해 활성화할 수 있습니다.
언급URL : https://stackoverflow.com/questions/38765595/woocommerce-shipping-free-shipping-is-available-doesnt-work
반응형
'programing' 카테고리의 다른 글
Windows에서 Git Bash 대 Windows Power Shell 대 Command 프롬프트의 차이점은 무엇입니까? (0) | 2023.11.05 |
---|---|
워드프레스필터가추가되지않음 (0) | 2023.11.05 |
MySQL JDBC 드라이버 msi 설치 (0) | 2023.11.05 |
자바스크립트를 통한 버튼 클릭시 태그 href 변경 방법 (0) | 2023.11.05 |
jQuery로 상자 그림자를 애니메이션화하는 올바른 방법 (0) | 2023.11.05 |