dongruan6001
2018-08-28 11:11
浏览 33
已采纳

WooCommerce - 重复订单的不同送货方式

I am developing a site with the following plugins:

  • WooCommerce
  • WooCommerce Subscriptions
  • Pakkelabels.dk for WooCommerce

"Pakkelabels.dk" is a packaging label plugin for carriers in Denmark. This plugin is using the standard WooCommerce filters and hooks to add additional shipping methods.

I am using a mixed checkout. The cart totals currently looks like this:

enter image description here

This is what I wan't to do

For recurring orders I wan't to limit the shipping methods to just "DAO Pakkeshop" and "Local pick up" (sorry for the Danish language in the image).

I have added this to functions.php, which unsets the shipping methods I don't wan't to have, when a specific product ID (the subscription product) is in the cart:

add_filter( 'woocommerce_package_rates', 'hide_shipping_methods_woo_sg', 10, 2 );
function hide_shipping_methods_woo_sg( $rates, $package ) {

    $product_id = get_field('product_auto_cart', 'option');

    if($product_id){
        $product_cart_id = WC()->cart->generate_cart_id( $product_id );
        $in_cart = WC()->cart->find_product_in_cart( $product_cart_id );

        if($in_cart) {
            unset( $rates['pakkelabels_shipping_dao_direct'] );
            unset( $rates['pakkelabels_shipping_gls_private'] );
            unset( $rates['pakkelabels_shipping_gls_business'] );
            unset( $rates['pakkelabels_shipping_gls'] );
            unset( $rates['pakkelabels_shipping_pdk'] );
            unset( $rates['pakkelabels_shipping_postnord_private'] );
            unset( $rates['pakkelabels_shipping_postnord_business'] );
            // unset( $rates['local_pickup:19'] );
        }
        return $rates;
    }
}

My problem is, that this removes the shipping methods for both the order and recurring order, as you can see on the image.

I need some sort of conditional, so that I can target only the recurring order shipping methods and unset those.

How can I achieve this?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题