Tagged: color picker, Product, woocommerce
-
AuthorPosts
-
October 7, 2017 at 6:05 am #861316
THIS IS NOT A SUPPORT REQUEST, IT’S JUST THE TIP BRO
If you’re using the Advanced Layout option to build your WooCommerce product pages, here is a simple way to include a custom color picker that will output the hex code. This is great for products where you offer a custom color option. Note, this won’t automatically put the hex code into any input boxes, but it will allow your customers to find the right color so they can copy/paste the code into the appropriate field. Once you add the code below to your child theme’s functions.php file and have edited it to reflect the script file locations, you can place the shortcode into a code snippet widget and place wherever you want. I used the shortcode in conjunction with an iconbox field so I could give directions.
You will need to download, then upload a few simple javascript files….then adjust the code below to reflect the location. Feel free to scan the files for errors prior to uploading to your server…always a smart thing to do.
DOWNLOADHere is an example…
// Add color picker script to header add_action('wp_head','get_custom_color'); function get_custom_color( ){ echo '<script src="[replace with direct location to file - custom-color.js]"></script>'; echo '<script src="[replace with direct location to file - jscolor.js]"></script>'; } // Create color picker shortcode function get_colorpicker() { $misccode = "{onFineChange:'update(this)',valueElement:null,value:'66ccff'}"; return '<div style="padding-top:8px!important;"><button class="jscolor '. $misccode .'" style="width:40px; height:40px; border: 1px solid #e1e1e1; float: left; margin: 0px 10px 15px 5px; border-radius:3px;"></button><div style="font-size:20px!important; margin-top:8px;"><span id="hex-str" style="color:#959595!important;"><span style="font-size:50px!important; vertical-align:text-top!important; color:#959595!important;">☚</span> Choose a color...</span></div></div>'; } add_shortcode( 'color_picker', 'get_colorpicker' );
- This topic was modified 7 years, 2 months ago by Kahil.
October 8, 2017 at 10:29 am #861508Hey Kahil,
Thank you yet again for sharing, much appreciated :-)
Best regards,
RikardNovember 29, 2017 at 5:33 am #882954UPDATE
I’ve taken this custom element and put it into an Advanced Layout Builder element to make it easier to create your custom pages. As a reminder, a color picker is a good addition to any product page where you’re selling something that has aspects where the customer can pick any color. All you have to do is follow the simple instructions on the page and you’re all set. -
AuthorPosts
- You must be logged in to reply to this topic.