-
AuthorPosts
-
June 23, 2024 at 3:30 pm #1457098
Hi Teacher,
Please how to change the product title when I choose an option ?
Thanks
June 23, 2024 at 5:32 pm #1457330Hey Aubin,
You will need a addon to do this, see this documentation for this one. This article points to some other plugins and options.
I found this code in this threadfunction custom_script() { ?> <script> jQuery( document ).ready( function( $ ) { var title_text = $( '.product-type-variable .product_title' ).text(); // get default title function add_variation_txt_to_title() { var new_title_text = ''; $( '.variations select' ).each( function() { new_title_text += ' ' + $( this ).find( ':selected' ).val(); // collect all variation selected <options> }) $( '.product-type-variable .product_title' ).text( title_text + new_title_text ); // set new title } add_variation_txt_to_title(); // call on load $( '.variations select' ).change( function() { // call on <select >change add_variation_txt_to_title(); }) }) </script> <?php } add_action( 'wp_footer', 'custom_script', 99 );
and it sort of works on my test site:
so give it a try. PLease note that not all plugins work with Enfold so you will need to test different plugin options to find one that works with your variable products the way you want.Best regards,
MikeJune 23, 2024 at 5:57 pm #1457346Thanks Mike.
Please where to add this code in enfold child ?
thanksJune 23, 2024 at 6:09 pm #1457347I added this function in the enfold child function.php . But it doesn’t work .
May I but this one ?
ThanksJune 23, 2024 at 6:36 pm #1457357Hi,
The WooCommerce Products by Attributes & Variations looks like it has a variation title field
which would be the easiest way, but make sure that you ask them if you can try it first, because some addons don’t work properly with Enfold. Some plugins have a free version on WordPress Plugins so I would also check there.
As for the script I posted above, my variation in my screenshot looks different that yours so perhaps that is a issue, and your site has a javascript error in your Simple Custom CSS and JS fore the search form, try disabling it and check again
document.getElementsByClassName('search-form')[0].innerHTML += '<input type="hidden" name="post_type" value="product">';
Best regards,
MikeJune 23, 2024 at 7:41 pm #1457380Thanks Mike for your support.
For sure , We have a different variations products. Look my own above.
“try disabling it and check again” How to do it please ?
Where to put this code ?
document.getElementsByClassName(‘search-form’)[0].innerHTML += ‘<input type=”hidden” name=”post_type” value=”product”>’;Last thing.
I bought the “show-products-by-attributes-variations-web-package-1.5.1” this one . How can I install this addons on enfold child please ?Thanks,
June 23, 2024 at 7:51 pm #1457384Hi,
No I don’t mean add that code, your page has that javascript error, try disabling this code from your site, I think it is in your Simple Custom CSS and JS plugin.
For the one you bought, you would install it as a pluginBest regards,
MikeJune 23, 2024 at 8:20 pm #1457389This reply has been marked as private.June 23, 2024 at 8:35 pm #1457391Hi,
Perhaps you can post a admin login in the Private Content area so we can look.Best regards,
MikeJune 23, 2024 at 8:40 pm #1457393This reply has been marked as private.June 23, 2024 at 8:56 pm #1457394Hi,
Thanks, now I see that you are using the ALB for the product with a text element for the title instead of the woocommerce title. Try creating a test product using the default editor and check.Best regards,
MikeJune 23, 2024 at 9:20 pm #1457395This reply has been marked as private.June 23, 2024 at 9:55 pm #1457397Hi,
I tried to create one for you but didn’t get the variations correct, please see the link below and adjust the variations. Do not use the Advanced Layout Builder, only use the woocommerce product fields:
Best regards,
MikeJune 23, 2024 at 10:26 pm #1457401This reply has been marked as private.June 23, 2024 at 11:27 pm #1457403Hi,
Ok, thank you, I see the Variation Title in the variation but it doesn’t seem to work on the frontend. I don’t see any errors that might point to a cause.
I did find the script that I posted above was in your child theme style.css so I moved it to your child theme functions.php and it changes the product title when a variation is picked, so that is good news:
Best regards,
MikeJune 23, 2024 at 11:40 pm #1457404Hi,
Thanks
That’s means it is not possible to do it with Advanced Layout Builder.
This is more complicated because all my website uses “Advanced Layout Builder”.
It is not to use a code block in ALB ?Thanks
June 24, 2024 at 12:09 am #1457406This reply has been marked as private.June 24, 2024 at 12:12 pm #1457949Hi,
The page that you linked to is not using the Enfold Advanced Layout Builder for the product, it is using the woocommerce product like in your test page, nonetheless I added some custom classes to your original /dji-mavic-3-classic/ product to try to get this to work.
In this text element:
I added the custom class product-type-variable :
and in the title H1 tag I added the custom class product_title, note that you must use the “text tab to add the class:
and now it works:
You will need to manually change your other products like this.Best regards,
MikeJune 25, 2024 at 1:50 am #1458540Thank very much
Ok for all -
AuthorPosts
- The topic ‘Changing title according’ is closed to new replies.