Created
March 26, 2017 10:25
-
-
Save bosunolanrewaju/b9d6304d19e1d2eab1b982a0f6f76b28 to your computer and use it in GitHub Desktop.
Code snippet for adding Local governments select field to WooCommerce cart shipping calculator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if ( class_exists( 'WC_All_Country_Counties' ) && | |
in_array( | |
'all-countries-counties-for-wc/all-countries-counties-for-wc.php', | |
apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) | |
) ) : | |
$current_lga = WC()->customer->local_government; | |
?> | |
<p class="form-row form-row-wide" id="calc_shipping_local_government_field"> | |
<select name="calc_shipping_local_government" id="shipping_local_government" placeholder="<?php esc_attr_e( 'Local Government', 'woocommerce' ); ?>"> | |
<?php | |
$lgas = ( new WC_All_Country_Counties )->wc_add_counties_local_government()[$current_cc][$current_r]; | |
foreach ( $lgas as $lkey => $lvalue ) | |
echo '<option value="' . esc_attr( $lkey ) . '" ' . selected( $current_lga, $lkey, false ) . '>' . __( esc_html( $lvalue ), 'woocommerce' ) .'</option>'; | |
?> | |
</select> | |
</p> | |
<?php endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: Override the default shipping-calculator.php file in your theme and paste this snippet just before the
calc_shipping
button. And use this version of the All-Countries-Counties-For-WooCommerce plugin.