Adapt shipping surcharge code [closed]

Here’s an untested modified version of your code: function woocommerce_bt_postcode_surcharge() { global $woocommerce; if ( is_admin() && ! defined( ‘DOING_AJAX’ ) ) return; if ( $woocommerce->customer->get_shipping_country() === ‘GB’ ) { $postcode = $woocommerce->customer->get_shipping_postcode(); if ( isset( $postcode ) && strtoupper( substr( trim( $postcode ), 0, 2 ) ) === ‘BT’ ) { $woocommerce->cart->add_fee( ‘Surcharge’, 35, … Read more

Woocommerce – Hide shipping at all, if only certain product or products with certain shipping class is in the cart

Solved it. Just remeber to add the same shipping class to all variations too. add_filter( ‘woocommerce_package_rates’, ‘custom_shipping_rates’, 100, 2 ); function custom_shipping_rates( $rates, $package ) { $shipping_class = 506; // HERE set the shipping class ID $found = false; $productsincart = count($package[‘contents’]); foreach( $package[‘contents’] as $cart_item ) { if ($productsincart == 1 && $cart_item[‘data’];->get_shipping_class_id() == … Read more

wc_get_product_id_by_sku() returns 0 for products added programatically via update_post_meta

The problem was that I didn’t create product with WC_Product object. When I create product with this object it works. for instance $product = new WC_Product; $product->set_name(“my product”); $product->set_sku(“345678”); $product->save(); Then I can easity get the ID of the product by SKU $post_id = wc_get_product_id_by_sku(‘345678’);

Variant Item SKU as Product Code

So I was able to get the result I am looking for but in so doing I have an error in the php error log. I added the following code in the section I showed above where I thought needed to be set. The code is as follows. $items = $this->order->get_items(); // Line items can … Read more