The problem is that WC_Cart
get_shipping_packages()
method gives an array of shipping packages and the function wc_get_shipping_zone( $package )
expect to have as argument a unique package.
So you need to get only one package, using for example php reset()
function like:
// Get cart shipping packages
$shipping_packages = WC()->cart->get_shipping_packages();
// Get the WC_Shipping_Zones instance object for the first package
$shipping_zone = wc_get_shipping_zone( reset( $shipping_packages ) );
$zone_id = $shipping_zone->get_id(); // Get the zone ID
$zone_name = $shipping_zone->get_zone_name(); // Get the zone name
// Testing output
echo '<p>Zone id: ' . $zone_id . ' | Zone name: ' . $zone_name . '</p>';
Tested and works.
Related Posts:
- How to correctly add Javascript in functions.php
- How to add date range in woocommerce with code
- Remove Woocommerce product link
- Display sorting options dropdown when using WooCommerce product category shortcode
- Using Cookie Data For WP_Query Loop
- Woocommerce, recognize the loop of related products
- WooCommerce Link to Product Category
- Output a WooCommerce product custom field in WooCommerce using get_post_meta()
- Append a term to WooCommerce product existing product category terms
- using woocommerce_template_single_add_to_cart in shop-loop – javascript issues [closed]
- Listing and displaying WooCommerce Shipping Zones in the frontend? [closed]
- How to prevent those PHP variables from being cached on WordPress?
- Setting All Drafts to ‘exclude-from-catalog’ in WooCommerce
- Woocommerce – Filter Variable Products by Variation Attributes and Variations Regular Price
- How do you add customer capability after Woocommerce purchase?
- Change sign up fee in cart for subscription products WooCommerce
- Make the first item as default on Woocommerce product category items list
- WooCommerce Related Products by Attribute
- Image as Sales Badge
- dividing sub-categories by parent category – WordPress
- Modify HTML structure of fields in woocommerce checkout form
- How to get all shipping rates and costs without session in woocommerce?
- Display a specific category of products in shop page and disable code for specific actions
- Trying to build simple deposit code that hooks into woocommerce
- how to fix error “called incorrectly, should not be accessed directly”?
- How to auto fetch customer details in Woocommerce in checkout page
- How can I get the values of my WordPress $wpdb query in Jquery?
- I want to add custom add to cart link [closed]
- Trouble checking if custom woocommerce checkout field is empty or not
- Validation algorithm in checkout field
- How do I remove the product thumbnail link from a specific div in Woocommerce? [closed]
- echo something inside a shortcode
- require_once() if a product in woocommerce contains a tag [closed]
- Can a plugin redirect product page based on IF condition?
- How do I change this function from two returns to one string to show sku and dimensions in WooCommerce cart?
- Remove page title in product page using a function
- woocommerce specific quantities for product
- Call WC_Product get_price()?
- woocommerce related product title length
- WordPress site with embedded menu – gives You don’t have permission to access /wp-content/themes/xxx/taxonomy-redirect.php on this server
- Woocommerce custom Plugin in wordpress [closed]
- How to separate product payment and shipping payment in WooCommerce checkout? [closed]
- Output product category link from WP_Query
- How to work Woocommerce pagination inside shortcode?
- How to get woocommerce orders with get_posts method in a shortcode
- Variation prices breakdown only for single product page
- Woocommerce disable order item link (backend) [closed]
- Set all WooCommerce Products to Simple, Virtual & Downloadable
- Undefined array key 0 wp-includes/capabilities.php on line 76
- How do I know if the user is a customer?
- Change the URL of an image from wp_get_attachment_image_src for Product Posts based on Category
- Combine change Email WordPress and woocommerce emails template
- I want to fusion the product columns in email table order
- WooCommerce is_product_category() not working
- Woocommerce Product page add on checkbox and price
- How to set Nav as a default menu in wordpress
- Best way to use variables in multiple functions?
- Display all categories including sub categories under a list ul
- How do I programmatically add ‘reviews_allowed’ to WooCommerce product?
- Adding new divs with custom classes to products on WooCommerce shop page [closed]
- Get product price in a different currency using WooCommerce Currency Switcher
- Discount in the specific product title using keyword ( Woocoommerce )
- Place product field value as variable in php
- Adding product permalink on admin order page throwing error
- How to override WooCommerce Order Item Meta with data from Cart?
- How to get total gross revenue for current month in the woocommerce dashboard status widget
- Add custom attribute to product’s HTML to woocommerce cart page
- Change WooCommerce template for PDF – access to custom field
- How can i style “echo apply_filters”
- Get all woocommerce product names with price and show using core php
- Add custom ID attribute to all woocommerce products on archive pages
- Put a span class in the shortened product title
- How to properly create multiple conditions to redirect users roles to different pages
- Add missing alt tag to featured images for “storefront” theme
- How can i put php code on the wordpress page?
- Sort WooCommerce data with WP-CRON?
- Display specific main Sub Nav on Woocommerce product pages
- How to detect if a revision was made by woocommerce or wordpress?
- Need Quick Help With Product Category Page
- How do I prevent a folder from reappearing in my home directory?
- jQuery doesn’t work in my php snippet
- Use WP_Query Data In Cookie
- How to add custom checkout field in user details mail template
- How to set up and use a custom upload directory for post type ‘product’
- How to get the rating value of each comment
- Add specific phrase after every product title including the discounted price? [closed]
- Display Sale Price Before Regular Price (WooCommerce)
- How keep woocommerce users separeted in multisite install and keep admins on network
- Setting WooCommerce currency programmatically
- Exclude specific product tags from related products in WooCommerce 3+ [closed]
- WooCommerce Orders pagination
- Product Category Page in Full Width
- After declaring woocommerce theme support products are no longer displayed
- WooCommerce – Show ‘Sales’ badge on variable products where only some variations have sales price [closed]
- How to create a container in php then customise it in CSS
- WCFM Custom form
- Hide child of parent categories already hidden with “get_terms_args” – Woocommerce
- Find owner of coupon
- Removing the add to cart button from specific product pages
- Add text below WooCommerce short description if metabox value is true