2016-11-30 6 views
0

同様の質問がありましたが、代わりに特定の出荷クラスでこのコードを実装したいと考えています。ここでは、コードは次のようになります。特定の出荷クラスに基づくWooCommerceチェックアウトメッセージ

add_action('woocommerce_after_checkout_form', 'allclean_add_checkout_content', 12); 
function allclean_add_checkout_content() { 
    // set your special category name, slug or ID here: 
    $special_cat = 'special_category'; 
    $bool = false; 
    foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) { 
     $item = $cart_item['data']; 
     if (has_term($special_cat, 'product_cat', $item->id)) 
      $bool = true; 
    } 
    // If the special cat is detected in one items of the cart 
    // It displays the message 
    if ($bool) 
     echo '<div class="checkoutdisc">This is Your custom message displayed.</div>'; 

答えて

0

add_action('woocommerce_after_checkout_form', 'allclean_add_checkout_content', 12); 
 
function allclean_add_checkout_content() { 
 
    // set your special category name, slug or ID here: 
 
    $shippingclass = array('cut'); 
 
    $bool = false; 
 
    foreach (WC()->cart->get_cart() as $cart_item_key => $values) { 
 
\t $shipping_class = get_the_terms($values['variation_id'], 'product_shipping_class'); 
 

 
     if (isset($shipping_class[0]->slug) && in_array($shipping_class[0]->slug, $shippingclass)) { 
 
      $bool = true; 
 
    } 
 
    // If the special cat is detected in one items of the cart 
 
    // It displays the message 
 
    if ($bool) 
 
     echo '<div class="example1"><h3>Items in your cart can be cut to save on shipping. List which items you want cut in your order notes.</h3></div>'; 
 
} 
 
}

関連する問題