Skip to content

Instantly share code, notes, and snippets.

@bolderelements
Created October 10, 2020 21:55
Show Gist options
  • Save bolderelements/c4751a7d12dc960cb37a909dade0bdd6 to your computer and use it in GitHub Desktop.
Save bolderelements/c4751a7d12dc960cb37a909dade0bdd6 to your computer and use it in GitHub Desktop.
Get selection and save as shipping meta data
/**
* Find the custom column selection when calculating shipping
*
* @return string
*/
function betrs_add_custom_data_shipping_array( $shipping_options, $option, $option_ID, $row_ID ) {
// find selected value from table
$selection = ( isset( $option['rows'][ $row_ID ]['provider'] ) ) ? sanitize_text_field( $option['rows'][ $row_ID ]['provider'] ) : '';
// add to shipping option
if( $selection != '' ) {
$shipping_options['provider'] = $selection;
}
return $shipping_options;
}
add_filter( 'betrs_processed_rate', 'betrs_add_custom_data_shipping_array', 10, 4 );
/**
* Add provider to meta data if selected.
*
* @return void
*/
function betrs_modify_shipping_rate_meta( $meta_data, $rate ) {
// check if the provider has been selected
if( ! empty( $rate['provider'] ) ) {
$meta_data['provider'] = sanitize_text_field( $rate['provider'] );
}
return $meta_data;
}
add_filter( 'betrs_shipping_rate_meta', 'betrs_modify_shipping_rate_meta', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment