• Resolved EasyNT

    (@easynt)


    We have shipping costs calculated by weight. For that we have defined different shipping methods per shipping zone (i.e. shipping method 2kg, shipping method 10kg, and so on). Then we have a filter in our functions.php where we select the shipping costs according to the weitht of the order:

    add_filter( ‘woocommerce_package_rates’, ‘my_woocommerce_shippingrates’, 9999, 2 );

    function my_woocommerce_shippingrates( $rates, $package ) {

      if ( WC()->cart->cart_contents_weight <= 2 ) {

        if ( isset( $rates[‘flat_rate:9’] ) ) unset( $rates[‘flat_rate:10’], $rates[‘flat_rate:11’], $rates[‘flat_rate:12’], $rates[‘flat_rate:14’], $rates[‘flat_rate:15’], $rates[‘flat_rate:16’], $rates[‘flat_rate:17’], $rates[‘flat_rate:18’], $rates[‘flat_rate:19’], $rates[‘flat_rate:20’], $rates[‘flat_rate:21’], $rates[‘flat_rate:22’], $rates[‘flat_rate:23’], $rates[‘flat_rate:24’], $rates[‘flat_rate:25’] );

        } elseif ( WC()->cart->cart_contents_weight > 2 && WC()->cart->cart_contents_weight <= 10 ) {

    ? ? if ( isset( $rates[‘flat_rate:10’] ) ) unset( $rates[‘flat_rate:9’], $rates[‘flat_rate:11’], $rates[‘flat_rate:12’], $rates[‘flat_rate:14’], $rates[‘flat_rate:15’], $rates[‘flat_rate:16’], $rates[‘flat_rate:17’], $rates[‘flat_rate:18’], $rates[‘flat_rate:19’], $rates[‘flat_rate:20’], $rates[‘flat_rate:21’], $rates[‘flat_rate:22’], $rates[‘flat_rate:23’], $rates[‘flat_rate:24’], $rates[‘flat_rate:25’] );

    etc.

      return $rates;

    }

    Google Listings & Ads ignores that and seems to always pick the most expensive shipping method. How can we fix that?

Viewing 1 replies (of 1 total)
  • Hi @easynt

    we have a filter in our functions.php where we select the shipping costs according to the weitht of the order

    Please note that writing or providing custom code is not within the scope of our support policy. If you are still having problems, we recommend asking development questions on the #developers channel of the WooCommerce Community Slack. Many of our developers hang out there and will be able to offer insights into your question. You can also seek help from the following:

    I wish I could help more, but hopefully, this gets you going in the right direction to get the job done.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.