Do you have any questions about the product?
Our experts are here to help!
jQuery(function($) { // Wait for the DOM to be fully loaded $(document).ready(function() { var history = []; $(window).on('hashchange', function() { history.push(location.hash); }); console.log("filter-color-20240224 MyLog-4","Filter Color", document.referrer, history); setInterval(function(){ if(document.referrer && window.location.href && document.referrer != window.location.href ){ console.log("MyLog 12", document.referrer, window.location.href); // window.location.href = window.location.href; }else{ console.log("MyLog 23", document.referrer, window.location.href); } }, 2000); // check_selected_color_slug(); }); jQuery(".viwcpf_filter-item a").click(function(){ console.log("MyLog-21", jQuery(this).attr('href')); }); function check_selected_color_slug(){ console.log('Log-22'); jQuery(".viwcpf_filter-item").each(function(){ if(jQuery(this).find("a.viwcpf_chosen").length){ var selectedColorSlug = jQuery(this).find('a').attr('data-term-slug'); if(selectedColorSlug){ console.log(selectedColorSlug); jQuery('ul.variations').each(function(){ console.log(selectedColorSlug, jQuery(this).find('.woo-variation-items-wrapper').html()); }); } } }); } }); ), then please use the "Add HTML Code" page, as this is a HTML code that links a JavaScript file. End of comment */ // Add this code to your theme's functions.php or a custom plugin file. // Hook into the 'wp_enqueue_scripts' action to enqueue custom JavaScript. function enqueue_custom_js() { // Enqueue your custom JavaScript file. wp_enqueue_script('custom-product-variation', get_template_directory_uri() . '/js/custom-product-variation.js', array('jquery'), null, true); // Localize JavaScript with necessary data for your script. $localized_data = array( 'ajax_url' => admin_url('admin-ajax.php'), ); wp_localize_script('woo_variation_swatches', '$variation_data', $localized_data); } add_action('wp_enqueue_scripts', 'enqueue_custom_js'); // Define an AJAX callback to get the variation image URL based on the selected color. function get_variation_image() { if (isset($_POST['color_attribute'])) { $variation_color = sanitize_text_field($_POST['color_attribute']); // Query the database to get the variation image URL. $image_url = get_variation_image_url($color_attribute); if ($image_url) { echo esc_url($image_url); } } die(); } add_action('wp_ajax_get_variation_image', 'get_variation_image'); add_action('wp_ajax_nopriv_get_variation_image', 'get_variation_image'); // You'll need to implement the function get_variation_image_url to retrieve the image URL based on the selected color. function get_variation_image_url($variation_color) { // Implement your logic to query the image URL for the selected color variation. // This can involve database queries or other methods specific to your setup. // Example: You can query the product variations and return the image URL for the matching color variation. // Replace this with your actual implementation. $image_url = get_field('color_image', $color_attribute); // Replace 'color_image' with your custom field name. return $image_url; }

Oops! Sorry, but your search returned no results!

Try again please, use the search form below.