• Resolved oscarsk

    (@oscarsk)


    Hi

    I need to display a text where the title is on the shipping zone in which the customer fits.

    I have made the code that shows the name of the shipping zone, but the title of the shipping zone does not change when the customer changes his zip code.

    I have tried calling the php code using ajax but I have not been able to get it to work.

    Anyone have a solution to this?

    Script

    <script>
    	$(document).ready(function() {
    		$("#billing_postcode").keypress(function() {
    			$.get("postcode.php", function(data, status) {
    				$("#test").html(data);
    			})
    		});
    	});
    </script>

    postcode.php

    <?php
    
    $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_name = $shipping_zone->get_zone_name(); // Get the zone name
    
    echo $zone_name;
    
    • This topic was modified 3 years, 2 months ago by oscarsk.
Viewing 2 replies - 1 through 2 (of 2 total)
  • @oscarsk

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.
    
    I can also recommend <a href="https://developer.woocommerce.com/" rel="noopener" target="_blank">the WooCommerce Developer Resources Portal</a> for resources on developing for WooCommerce.
    
    You can also visit the <a href="https://www.facebook.com/groups/advanced.woocommerce/" rel="noopener" target="_blank">WooCommerce Facebook group</a> or the <code>#developers</code> channel of the <a href="https://woocommerce.com/community-slack/" rel="noopener" target="_blank">WooCommerce Community Slack</a>. We're lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Seems we’ve not had additional inputs on this thread. Thus, we encourage you to make use of the above resources.

    That said, I’ll go ahead and mark the thread as resolved but please feel free to create a new thread if you have further questions.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Get get_zone_name() with ajax’ is closed to new replies.