Skip to content

Instantly share code, notes, and snippets.

@jamesckemp
Created May 14, 2020 22:07
Show Gist options
  • Save jamesckemp/75a62f8851441825408734a369918bc8 to your computer and use it in GitHub Desktop.
Save jamesckemp/75a62f8851441825408734a369918bc8 to your computer and use it in GitHub Desktop.
/**
* Modify delivery slots labels.
*
* @param array $labels
* @param null|WC_Order $order
*
* @return array
*/
function iconic_modify_delivery_slots_labels( $labels, $order ) {
$chosen_shipping = $order ? iconic_get_order_shipping_method( $order ) : iconic_get_selected_shipping_method();
if ( ! $chosen_shipping ) {
return $labels;
}
if ( $chosen_shipping === 'local_pickup:4' ) {
$labels['details'] = __( 'Collection Details', 'iconic' );
$labels['date'] = __( 'Collection Date', 'iconic' );
$labels['select_date'] = __( 'Select a collection date', 'iconic' );
$labels['choose_date'] = __( 'Please choose a date for your collection.', 'iconic' );
$labels['choose_time_slot'] = __( 'Please choose a time slot for your collection.', 'iconic' );
}
return $labels;
}
add_filter( 'iconic_wds_labels', 'iconic_modify_delivery_slots_labels', 10, 2 );
/**
* Get order shipping method.
*
* @param WC_Order $order
*
* @return bool|string
*/
function iconic_get_order_shipping_method( $order ) {
$chosen_methods = $order->get_shipping_methods();
if ( empty( $chosen_methods ) ) {
return false;
}
$chosen_shipping = array_shift( $chosen_methods );
return sprintf( '%s:%s', $chosen_shipping->get_method_id(), $chosen_shipping->get_instance_id() );
}
/**
* Get selected shipping method.
*
* @return string|bool
*/
function iconic_get_selected_shipping_method() {
if ( is_admin() ) {
return false;
}
$chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
if ( empty( $chosen_methods ) ) {
return false;
}
return $chosen_methods[0];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment