1

woocommerceでUPS拡張機能を使用しています。UPS計算機をバイパスして、一部の商品を送料無料で提供する必要があります。これを行う良い方法の1つは、アイテムを「virtuaL」としてマークすることですが、その場合、アイテムは出荷する必要がありません。この商品の発送が必要です。チェックアウトページをカスタマイズして、配送フィールドを仮想アイテムに表示するように強制することはできましたが、実際の注文には保存されません。

UPS計算機をバイパスしながら、カスタム関数を作成したり、woocommerceファイルを変更して、チェックアウトプロセスで仮想アイテムの配送を強制する方法を知っている人はいますか?(他のアイテムは輸送のために計算される必要があります)

4

4 に答える 4

1

私は同じ問題を抱えていました。プラグインの作成者は、それはできないと答えました。それを行うにはコードを書く必要があります。

于 2013-03-31T15:24:22.583 に答える
0

私もまさにこれを必要としており、実行可能な解決策があります:

最初にfunctions.phpin"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 Shippingfree-shippingAdd New Shipping Class

次に、配送を"WooCommerce"->"Settings"->"Shipping"->"Flat Rate"有効にして " " セクションの下で、作成した " " クラスの隣に " "の値を入力します。私の場合、 " " も " " に設定しています。次に「」。Flat RateShipping Class Costs0.00Free ShippingCalculation TypePer ClassSave changes

そして最後に"WooCommerce"->"Settings"->"Shipping"->"Shipping Options"Shipping Methods「各オプションの左側にあるメニュー アイコンを使用して、ドラッグして並べ替えることができます)。" "。Flat RateSelection PrioritySave Changes

次に、送料無料にしたい商品の 1 つを編集し、「Product Data"->"Shipping」セクションに移動して、配送クラスを「Free Shipping」(作成した新しいクラス) に変更します。次に、" Update" その製品で変更を保存します。次に、それもカートに追加し、通常の送料無料でない他のアイテムもカートに追加します.

テスト。

ショッピング カートにそれぞれの種類の商品が入っている場合でも、送料無料の商品には独自の配送「パッケージ」行 (「Shipping #1」および「 」) があり、送料を請求する必要がある商品とは別に表示されるはずです。Shipping #2

または、「 Per Product Shipping 」と呼ばれる完全な有料プラグインを試すこともできます。

または、この無料のプラグインも同様に機能する可能性があります (約束はありません)。

于 2015-12-14T23:39:40.647 に答える
0

商品の送料を「無料」にするのに役立つと思われる別の方法 (および私が過去に使用した方法) は、商品を割引するクーポンを作成することです (「仮想」とマークしないでください)。その価格から送料を引いたものまで。

たとえば、商品が $100 で送料が $10 (合計 $110) の場合、その商品専用のクーポンを作成すると、商品と送料の合計が $100 になります。

woocommerce でクーポンを作成する方法は既にご存じだと思います (その方法を一新する必要がある場合は、このページが役立ちます)。送料無料にしたい特定の商品にクーポンを適用するには、 [使用制限] -> [商品] に移動し、「送料無料」(この場合は割引) にしたい特定の商品を指定します。

ユーザーがチェックアウト時にこのクーポン コードを入力する手間を省くために、次のコードを functions.php に追加できます。

//Check for specific products then discount to adjust for 'free' shipping.

function my_free_shipping(){
//variables.
global $woocommerce;
$coupon_code = 'free-shiping';
$products= array('1', '2'); //products (ID's) to have discounted shipping.

//get the cart contents.
$cart_item = $woocommerce->cart->get_cart();
//loop through the cart items looking for the products in $products.
    foreach ($cart_item as $key => $item){
        //check if the cart items match to any of those in the array.
        if(in_array($item['product_id'], $products)){       
            //apply discount.
            $woocommerce->cart->add_discount(sanitize_text_field($coupon_code));
        }
    }
} 

add_action('init', 'my_free_shipping');   

このコードを UPS 拡張機能でまだテストしていないことに注意してください。ただし、自由に変更して試してみてください。

この投稿があなたの役に立てば幸いです。

于 2015-12-15T06:10:53.853 に答える