AI Verified

Name

WooCommerce Single Product Variation Radio

About

This will convert the Variation Dropdowns to be Radio Buttons for WooCommerce Single Product.

Language

PHP

Rating

Voted: 0 by 0 user(s)

How to Setup Snippet

Additional CSS should be added to the 'Add to Cart' widget: CSS for Radio Circles = CSS for Inline Radio Circle = CSS for Inline Coloured Radio Circle =

Codevault

WebSquadron

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: 6.4

Our AI bot has checked this snippet is compatable up to wordpress version: 6.1

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

History

Last modified:

13/03/2024

Important Note

This snippet has the following status:

AI Verified

This snippet has been tested by our AI bot, see any comments below.

AI Bot Comments:

Found 0 vulnerabilities

WooCommerce Single Product Variation Radio

 
                    
1add_filter('woocommerce_dropdown_variation_attribute_options_html', 'variation_changes', 20, 2);
2function variation_changes($html, $args) {
3 if (empty($args['options']) || !$args['product']) {
4 return $html; // Return original HTML if no options or product is provided
5 }
6 
7 $name = !empty($args['name']) ? $args['name'] : 'attribute_' . sanitize_title($args['attribute']);
8 
9 // Start the radio button markup
10 $radios = '<div class="variation-changes-container">';
11 
12 // Loop through each option
13 foreach ($args['options'] as $option) {
14 // Generate a class name based on the option for specific styling
15 $class = sanitize_title($option); // Creates a valid HTML class from the option value
16 
17 // Determine if the option is selected
18 $checked = checked($args['product']->get_variation_default_attribute($args['attribute']), $option, false);
19 
20 // Create the radio button with a class for the label based on the option
21 $radios .= sprintf('<label class="%1$s"><input type="radio" name="%2$s" value="%3$s" %4$s class="%1$s"> %5$s</label><br>',
22 esc_attr($class),
23 esc_attr($name),
24 esc_attr($option),
25 $checked,
26 esc_html(apply_filters('woocommerce_variation_option_name', $option))
27 );
28 }
29 
30 $radios .= '</div>'; // End the radio button markup
31 
32 return $html . $radios;
33}

0

Related Snippets

Please see some snippets below related to this snippet..

WooCommerce

AI Verified

0

Remove WooCommerce breadcrumbs on all pages

Added: 1 year ago

Last Updated: 1 year ago

WooCommerce

AI Verified

0

Disable WooCommerce Ajax Cart Fragments On Homepage

Added: 1 year ago

Last Updated: 1 year ago

WooCommerce

AI Verified

0

Gutenberg for Woocommerce product pages

Added: 1 year ago

Last Updated: 1 year ago

Want to use Gutenberg for Woocommerce? This snippet will make it happen (but might be useless in the future though)

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

Performance

AI Verified

32

Remove Unused Javascript

Added: 1 year ago

Last Updated: 3 days ago

Remove Unused Javascript - and improve your Page Speed Insight Score

WooCommerce

Pro Verified

10

Deactivate some WooCommerce Checkout Fields

Added: 1 year ago

Last Updated: 2 weeks ago

Deactivate some WooCommerce Checkout Fields from showing

Elementor

AI Verified

6

CSS Grid Aid

Added: 8 months ago

Last Updated: 1 month ago

This can be used for any WordPress Builder to aid working with CSS Grids.