Last active
October 10, 2020 21:41
-
-
Save bolderelements/5a3194048cb38d975144f11e69632ace to your computer and use it in GitHub Desktop.
Add form field to custom column in the Table of Rates
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
/** | |
* 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