Skip to content

Instantly share code, notes, and snippets.

@PechenkiUA
Last active September 28, 2023 13:47
Show Gist options
  • Save PechenkiUA/d511a1f029b53cbb575c67eb395697d4 to your computer and use it in GitHub Desktop.
Save PechenkiUA/d511a1f029b53cbb575c67eb395697d4 to your computer and use it in GitHub Desktop.
shiping method WC change to dropdown
<?php if ( 1 === count( $available_methods ) ) :
$method = current( $available_methods );
echo wp_kses_post( wc_cart_totals_shipping_method_label( $method ) );
?>
<input type="hidden" name="shipping_method[<?php echo esc_attr( $index ); ?>]"
data-index="<?php echo esc_attr( $index ); ?>"
id="shipping_method_<?php echo esc_attr( $index ); ?>"
value="<?php echo esc_attr( $method->id ); ?>" class="shipping_method"/>
<?php else: ?>
<select name="shipping_method[<?php echo esc_attr( $index ); ?>]"
data-index="<?php echo esc_attr( $index ); ?>"
id="shipping_method_<?php echo esc_attr( $index ); ?>" class="shipping_method">
<?php foreach ( $available_methods as $method ) : ?>
<option value="<?php echo esc_attr( $method->id ); ?>" <?php selected( $method->id, $chosen_method ); ?>><?php echo wp_kses_post( wc_cart_totals_shipping_method_label( $method ) ); ?></option>
<?php endforeach; ?>
</select>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment