• Resolved dennis89e

    (@dennis89e)


    Hi,

    I want to get the color swatches for a specific product. Is there already a function for this?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support fizanzvai

    (@fizanzvai)

    Hi,

    Thanks for reaching out to us.

    Please try the below snippet using a plugin called Code Snippets:

    add_filter('default_woo_variation_swatches_single_product_dropdown_html', function($default){
    global $product;
    $target = [14]; //Insert the product id’s inside the target to display default dropdown rather than swatches. For example: [14,45]
    if( in_array( $product->get_id(), $target ) ){
    return true;
    }
    return $default;
    }, 10, 1);

    You can also add the above code inside your current child theme’s functions.php file.

    Note: It is recommended to add the Custom Code to the child theme’s functions.php file, to avoid any data loss while updating the Parent Theme.

    Hope to hear from you soon.

    Thank You

    Thread Starter dennis89e

    (@dennis89e)

    Hi fizanzvai,

    I added this filter but nothing happened. Also, I don’t know if you understand what I mean.

    https://stackoverflow.com/questions/62099351/wordpress-woocommerce-show-attributes-on-shop-page

    I tried the code from the link, and that works fine. But I don’t want to show the name of the colors, I want to show the swatches. Is there a shortcut/function for that to get the swatches of a product?

    Hope to hear from you.

    Dennis

    Plugin Support fizanzvai

    (@fizanzvai)

    Hi,

    I want to get the color swatches for a specific product.

    I thought you wanted to display the dropdown for some products and want to show swatches for some products.

    But from the “stackoverflow link”, I can see you want to display swatches on the archive/shop page. Unfortunately, it is not available in our free/standard version.

    Thank You

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Get the swatches for a specific product’ is closed to new replies.