programing

woocommerce에서 무료 배송을 위한 최소 주문량을 얻는 방법

nicescript 2023. 3. 8. 23:42
반응형

woocommerce에서 무료 배송을 위한 최소 주문량을 얻는 방법

무료 배송에 필요한 최소 주문량을 가져오려면 어떻게 해야 합니까?woocommerce_free_shipping_min_amount관리패널 woocommerce -> 설정 -> 배송비 무료배송비 -> 최소주문금액)에서 woocommerce로 설정되어 있는 것은 무엇입니까?

이 가격을 프런트 엔드에 표시하고 싶습니다.

이 값은 다음 위치에 저장됩니다.option비밀리에woocommerce_free_shipping_settings에 의해 로드되는 어레이입니다.WC_Settings_API->init_settings().

직접 액세스하고 싶은 경우는, 다음과 같이 할 수 있습니다.get_option():

$free_shipping_settings = get_option( 'woocommerce_free_shipping_settings' );
$min_amount = $free_shipping_settings['min_amount'];

WooCommerce 버전 2.6 이후로는 인정된 답변은 더 이상 작동하지 않습니다.출력은 계속 나오지만 새로 도입된 Shipping Zone을 사용하지 않기 때문에 출력은 잘못된 것입니다.

특정 구역에서 무료 배송을 위한 최소 지출 금액을 얻기 위해 제가 함께 설정한 이 기능을 사용해 보십시오.

/**
 * Accepts a zone name and returns its threshold for free shipping.
 *
 * @param $zone_name The name of the zone to get the threshold of. Case-sensitive.
 * @return int The threshold corresponding to the zone, if there is any. If there is no such zone, or no free shipping method, null will be returned.
 */
function get_free_shipping_minimum($zone_name = 'England') {
  if ( ! isset( $zone_name ) ) return null;

  $result = null;
  $zone = null;

  $zones = WC_Shipping_Zones::get_zones();
  foreach ( $zones as $z ) {
    if ( $z['zone_name'] == $zone_name ) {
      $zone = $z;
    }
  }

  if ( $zone ) {
    $shipping_methods_nl = $zone['shipping_methods'];
    $free_shipping_method = null;
    foreach ( $shipping_methods_nl as $method ) {
      if ( $method->id == 'free_shipping' ) {
        $free_shipping_method = $method;
        break;
      }
    }

    if ( $free_shipping_method ) {
      $result = $free_shipping_method->min_amount;
    }
  }

  return $result;
}

위의 기능을 함수에 넣습니다.php 및 다음과 같은 템플릿으로 사용합니다.

$free_shipping_min = '45';

$free_shipping_en = get_free_shipping_minimum( 'England' );
if ( $free_shipping_en ) {
    $free_shipping_min = $free_shipping_en;
}

echo $free_shipping_min;

이게 도움이 됐으면 좋겠네요.

언급URL : https://stackoverflow.com/questions/26582039/how-to-get-minimum-order-amount-for-free-shipping-in-woocommerce

반응형