Skip to content

Instantly share code, notes, and snippets.

@bolderelements
Last active October 10, 2020 21:41
Show Gist options
  • Save bolderelements/5a3194048cb38d975144f11e69632ace to your computer and use it in GitHub Desktop.
Save bolderelements/5a3194048cb38d975144f11e69632ace to your computer and use it in GitHub Desktop.
Add form field to custom column in the Table of Rates
/**
* Add form field to custom column in the Table of Rates
*
* @return string
*/
function betrs_add_column_data( $content, $item ) {
// find previously saved value
$saved = ( isset( $item['provider'] ) ) ? sanitize_text_field( $item['provider'] ) : '';
// array of shipping providers
$providers = array(
'US Postal Service',
'FedEx',
'UPS'
);
// setup form field
$content = '<select name="provider[' . $item['option_ID'] . '][' . $item['row_ID'] . ']">';
foreach( $providers as $name ) {
$content .= '<option ' . selected( $name, $saved, false ) . '>' . $name . '</option>';
}
$content .= '</select>';
return $content;
}
add_filter( 'betrs_shipping_table_column_provider', 'betrs_add_column_data', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment