Skip to content

Instantly share code, notes, and snippets.

@RiaanKnoetze
Created October 30, 2020 16:09
Show Gist options
  • Save RiaanKnoetze/274806f768cb0af6f8876ef937758770 to your computer and use it in GitHub Desktop.
Save RiaanKnoetze/274806f768cb0af6f8876ef937758770 to your computer and use it in GitHub Desktop.
Convert Product Addon Field to Select2
<!-- Add following snippet to "Header & Footers WordPress Plugin. Replace wc.local with your own website URL -->
<link rel='stylesheet' id='select2-css' href='https://wc.local/wp-content/plugins/woocommerce/assets/css/select2.css?ver=4.6.1' media='all' />
<script src="https://wc.local/wp-content/plugins/woocommerce/assets/js/selectWoo/selectWoo.full.min.js?ver=1.0.6" id="selectWoo-js"></script>
<script>
jQuery( document ).ready(
function ($) {
$( '.wc-pao-addon-select' ).filter( ':not(.enhanced)' ).each(
function() {
jQuery( this ).select2(
{
width: '100%',
}
).addClass( 'enhanced' );
}
);
}
);
</script>
<style>
.select2.select2-container {
width: 100% !important;
}
.select2.select2-container .select2-selection {
border: 1px solid #ccc;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
height: 34px;
margin-bottom: 15px;
outline: none;
transition: all 0.15s ease-in-out;
}
.select2.select2-container .select2-selection .select2-selection__rendered {
color: #333;
line-height: 32px;
padding-right: 33px;
}
.select2.select2-container .select2-selection .select2-selection__arrow {
background: #f8f8f8;
border-left: 1px solid #ccc;
-webkit-border-radius: 0 3px 3px 0;
-moz-border-radius: 0 3px 3px 0;
border-radius: 0 3px 3px 0;
height: 32px;
width: 33px;
}
.select2.select2-container.select2-container--open .select2-selection.select2-selection--single {
background: #f8f8f8;
}
.select2.select2-container.select2-container--open .select2-selection.select2-selection--single .select2-selection__arrow {
-webkit-border-radius: 0 3px 0 0;
-moz-border-radius: 0 3px 0 0;
border-radius: 0 3px 0 0;
}
.select2.select2-container.select2-container--open .select2-selection.select2-selection--multiple {
border: 1px solid #34495e;
}
.select2.select2-container.select2-container--focus .select2-selection {
border: 1px solid #34495e;
}
.select2.select2-container .select2-selection--multiple {
height: auto;
min-height: 34px;
}
.select2.select2-container .select2-selection--multiple .select2-search--inline .select2-search__field {
margin-top: 0;
height: 32px;
}
.select2.select2-container .select2-selection--multiple .select2-selection__rendered {
display: block;
padding: 0 4px;
line-height: 29px;
}
.select2.select2-container .select2-selection--multiple .select2-selection__choice {
background-color: #f8f8f8;
border: 1px solid #ccc;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
margin: 4px 4px 0 0;
padding: 0 6px 0 22px;
height: 24px;
line-height: 24px;
font-size: 12px;
position: relative;
}
.select2.select2-container .select2-selection--multiple .select2-selection__choice .select2-selection__choice__remove {
position: absolute;
top: 0;
left: 0;
height: 22px;
width: 22px;
margin: 0;
text-align: center;
color: #e74c3c;
font-weight: bold;
font-size: 16px;
}
.select2-container .select2-dropdown {
background: transparent;
border: none;
margin-top: -5px;
}
.select2-container .select2-dropdown .select2-search {
padding: 0;
}
.select2-container .select2-dropdown .select2-search input {
outline: none;
border: 1px solid #34495e;
border-bottom: none;
padding: 4px 6px;
}
.select2-container .select2-dropdown .select2-results {
padding: 0;
}
.select2-container .select2-dropdown .select2-results ul {
background: #fff;
border: 1px solid #34495e;
}
.select2-container .select2-dropdown .select2-results ul .select2-results__option--highlighted[aria-selected] {
background-color: #3498db;
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment