私もまさにこれを必要としており、実行可能な解決策があります:
最初にfunctions.php
in"Appearance"->"Editor"->"Theme Functions"
に移動し、次のコードを追加します (最初に「子テーマ」を使用することを強くお勧めします。そのため、テーマを変更しないでくださいfunctions.php
...または、代わりにカスタム プラグインを作成することもできます)。
/* Puts items with "free-shipping" shipping class into a different shipping package. */
function free_woocommerce_cart_shipping_packages( $packages ) {
// Reset the packages
$packages = array();
// Free items
$freeshipping_items = array();
$regular_items = array();
// Sort free from regular (replace "free-shipping" below with the shipping class slug you actually use).
foreach( WC()->cart->get_cart() as $item ) {
if( $item['data']->needs_shipping() ) {
if( $item['data']->get_shipping_class() == 'free-shipping' ) {
$freeshipping_items[] = $item;
}
else {
$regular_items[] = $item;
}
}
}
// Put inside packages:
if( $freeshipping_items ) {
$packages[] = array(
'ship_via' => array( 'flat_rate' ),
'contents' => $freeshipping_items,
'contents_cost' => array_sum(wp_list_pluck($freeshipping_items, 'line_total')),
'applied_coupons' => WC()->cart->applied_coupons,
'destination' => array(
'country' => WC()->customer->get_shipping_country(),
'state' => WC()->customer->get_shipping_state(),
'postcode' => WC()->customer->get_shipping_postcode(),
'city' => WC()->customer->get_shipping_city(),
'address' => WC()->customer->get_shipping_address(),
'address_2' => WC()->customer->get_shipping_address_2()
)
);
}
if( $regular_items ) {
$packages[] = array(
// 'ship_via' => array( 'usps' ),
'contents' => $regular_items,
'contents_cost' => array_sum(wp_list_pluck($regular_items, 'line_total')),
'applied_coupons' => WC()->cart->applied_coupons,
'destination' => array(
'country' => WC()->customer->get_shipping_country(),
'state' => WC()->customer->get_shipping_state(),
'postcode' => WC()->customer->get_shipping_postcode(),
'city' => WC()->customer->get_shipping_city(),
'address' => WC()->customer->get_shipping_address(),
'address_2' => WC()->customer->get_shipping_address_2()
)
);
}
return $packages;
}
add_filter('woocommerce_cart_shipping_packages', 'free_woocommerce_cart_shipping_packages');
次に、 に移動し、 " " というスラッグを使用して"Products"->"Shipping Classes"
" " という配送クラスを作成します(スラッグ名は、カスタム関数を関連付けるものです)。次に「」。Free Shipping
free-shipping
Add New Shipping Class
次に、配送を"WooCommerce"->"Settings"->"Shipping"->"Flat Rate"
有効にして " " セクションの下で、作成した " " クラスの隣に " "の値を入力します。私の場合、 " " も " " に設定しています。次に「」。Flat Rate
Shipping Class Costs
0.00
Free Shipping
Calculation Type
Per Class
Save changes
そして最後に"WooCommerce"->"Settings"->"Shipping"->"Shipping Options"
、Shipping Methods
「各オプションの左側にあるメニュー アイコンを使用して、ドラッグして並べ替えることができます)。" "。Flat Rate
Selection Priority
Save Changes
次に、送料無料にしたい商品の 1 つを編集し、「Product Data"->"Shipping
」セクションに移動して、配送クラスを「Free Shipping
」(作成した新しいクラス) に変更します。次に、" Update
" その製品で変更を保存します。次に、それもカートに追加し、通常の送料無料でない他のアイテムもカートに追加します.
テスト。
ショッピング カートにそれぞれの種類の商品が入っている場合でも、送料無料の商品には独自の配送「パッケージ」行 (「Shipping #1
」および「 」) があり、送料を請求する必要がある商品とは別に表示されるはずです。Shipping #2
または、「 Per Product Shipping 」と呼ばれる完全な有料プラグインを試すこともできます。
または、この無料のプラグインも同様に機能する可能性があります (約束はありません)。