Should be able to be done with radio buttons and enough CSS customization.
Thanks for the reply Michael. Well I tried to create a custom field and while I was able to render the markup, the post was not saving the meta data.
The code I used is given below:
function cmb2_render_onoffswitch( $field, $escaped_value, $object_id, $object_type, $field_type_object ) {
?>
<div class="onoffswitch">
<?php echo $field_type_object->input( array( 'type' => 'checkbox', 'class' => 'onoffswitch-checkbox', 'name' => 'onoffswitch', 'id' => 'myonoffswitch', 'value' => 'onoffswitch' ) ); ?>
<label class="onoffswitch-label" for="myonoffswitch">
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
</div>
<?php
}
add_action( 'cmb2_render_onoffswitch', 'cmb2_render_onoffswitch', 10, 5 );
I’d recommend a radio button over a checkbox, that way the user can only choose one or the other.
Is the for the frontend or the backend? If frontend, you may need to do the saving of the meta yourself, if I recall right. Check the blogpost link below specifically for this.
Some resources to try and get you better on your way:
https://github.com/WebDevStudios/CMB2/wiki
https://github.com/WebDevStudios/CMB2-Snippet-Library
https://webdevstudios.com/2015/03/30/use-cmb2-to-create-a-new-post-submission-form/