-
AuthorPosts
-
February 12, 2023 at 12:50 pm #1397633
Hi,
I would like to add the a WooCommere Attribute, under the woocommerce-product-details__short-description of single product page. (Please see img link on Private content)
Could you please help me?Best regards
OrianoFebruary 12, 2023 at 2:58 pm #1397644February 12, 2023 at 5:53 pm #1397659Hi Mike, i’m working in a local Mamp clone of the site?
Find in “Private content” the URL of thr site in production.Best regards
OrianoFebruary 12, 2023 at 7:31 pm #1397663Hi,
Thanks I found this article: Display Custom Products Attributes
When I tested it on my demo site by adding the attribute “author” to a product it showed the attribute as in your screenshot, please give a try.Best regards,
MikeFebruary 13, 2023 at 12:08 pm #1397732Hi Mike, thanks for your help.
but if I only want to display the “Autore” attribute?How must change this code:
function cw_woo_attribute(){ global $product; $attributes = $product->get_attributes(); if ( ! $attributes ) { return; }
Best regards,
OrianoFebruary 14, 2023 at 1:32 pm #1397911Hi,
Thanks for your patience, I found a different solution in my test I found that the “author” attribute must be set in the WooCommerce ▸ Attributes ▸ Add new attribute and not manually added on the product page in order to be named correctly.
Please note that the Slug “author” is not allowed because it is a reserved term, so we will use “authors”
This will name the attribute pa_authors so we can call it.
Then on the product page add the “value” for the attribute:
and this function in your child theme functions.php:add_action( 'woocommerce_single_product_summary', 'product_attribute_dimensions', 25 ); function product_attribute_dimensions(){ global $product; $taxonomies = array('pa_authors'); foreach($taxonomies as $taxonomy){ $value = $product->get_attribute( $taxonomy ); if ( $value ) { $label = get_taxonomy( $taxonomy )->labels->singular_name; echo '<p>' . $label . ': ' . $value . '</p>'; } } }
Then the attribute will show on the frontend:
Best regards,
MikeFebruary 16, 2023 at 9:45 am #1398184Hi Mike, thanks for your help.
Now the author name is also displayed below the short description.
But it would be necessary that the author’s name to be linked to its “author page”, as is the case with the author’s name appearing in the additional information:
It can be done? 😳
Best regards
OrianoFebruary 16, 2023 at 12:40 pm #1398205Hi,
Please remove the above solution and add this script to the end of your child theme functions.php file in Appearance ▸ Editor:function custom_script_pa_autore() { ?> <script> window.addEventListener('DOMContentLoaded', function() { (function($){ $('.shop_attributes .woocommerce-product-attributes-item--attribute_pa_autore').each(function() { $(this).clone().wrapInner('<p class="pa-autore"/>').children(0).unwrap().appendTo('.woocommerce-product-details__short-description').css({'margin':'0'}); $('.pa-autore .woocommerce-product-attributes-item__label').wrapInner('<p class="autore-label"/>').children(0).unwrap().css({'display':'inline-block','margin':'0'}); $('.pa-autore .woocommerce-product-attributes-item__value').wrapInner('<p class="autore-value"/>').children(0).unwrap().css({'display':'inline-block','margin':'0'}); $('.pa-autore .autore-value p').css({'margin':'0'}); }); })(jQuery); }); </script> <?php } add_action('wp_footer', 'custom_script_pa_autore');
Please ensure to copy the code from the forum and not an email notification so the symbols are not converted.
The expected results:
Best regards,
MikeFebruary 16, 2023 at 1:19 pm #1398209Hi Mike
now it’s almost perfect.One last detail.
I saw that I can edit the “.pa-author” css, and this is great.
But since book authors are fussy… we should add a colon after the word “Author”.
To obtain:
Author: Name SurnamePost scriptum: I hope this will also be useful for an upcoming demo of Enfold “Bookshop”
Best regards
OrianoFebruary 16, 2023 at 7:25 pm #1398256Hi,
Please add this css:.pa-autore > .autore-label:after { content: ": " }
After applying the css, please clear your browser cache and check.
Please ensure to copy the code from the forum and not an email notification so the symbols are not converted.Best regards,
MikeFebruary 17, 2023 at 9:16 am #1398315Hi Mike,
Thank you very much for your help.I do not exclude returning to this ticket for further implementations on this Enfold Bookshop.
But for now I’ll stop here and propose these changes to my client, who I think will be satisfied.Best regards,
OrianoEnfold x ever
February 17, 2023 at 12:00 pm #1398325Hi Mike
I’m still here…Would it be possible to add a second Attribute?
Example add also the attribute Curator?Best regards
OrianoFebruary 17, 2023 at 12:13 pm #1398328Hi,
Please update the live site as there is no attribute Curator, I assume the attribute class will be .woocommerce-product-attributes-item–attribute_pa_curator but I need to see it to test a new script.Best regards,
MikeFebruary 17, 2023 at 12:34 pm #1398329Hi Mike
the second attribute is “Curatore”.
See Private content for test url.Best regards
OrianoFebruary 17, 2023 at 2:03 pm #1398346Hi,
Thanks, try replacing the precious solution with this this one at the end of your child theme functions.php file in Appearance ▸ Editor:function custom_script_pa_autore_and_pa_curatore() { ?> <script> window.addEventListener('DOMContentLoaded', function() { (function($){ $('.shop_attributes .woocommerce-product-attributes-item--attribute_pa_autore').each(function() { $(this).clone().wrapInner('<p class="pa-autore"/>').children(0).unwrap().appendTo('.woocommerce-product-details__short-description').css({'margin':'0'}); $('.pa-autore .woocommerce-product-attributes-item__label').wrapInner('<p class="autore-label"/>').children(0).unwrap().css({'display':'inline-block','margin':'0'}); $('.pa-autore .woocommerce-product-attributes-item__value').wrapInner('<p class="autore-value"/>').children(0).unwrap().css({'display':'inline-block','margin':'0'}); $('.pa-autore .autore-value p').css({'margin':'0'}); }); $('.shop_attributes .woocommerce-product-attributes-item--attribute_pa_curatore').each(function() { $(this).clone().wrapInner('<p class="pa-curatore"/>').children(0).unwrap().appendTo('.woocommerce-product-details__short-description').css({'margin':'0'}); $('.pa-curatore .woocommerce-product-attributes-item__label').wrapInner('<p class="curatore-label"/>').children(0).unwrap().css({'display':'inline-block','margin':'0'}); $('.pa-curatore .woocommerce-product-attributes-item__value').wrapInner('<p class="curatore-value"/>').children(0).unwrap().css({'display':'inline-block','margin':'0'}); $('.pa-curatore .curatore-value p').css({'margin':'0'}); }); })(jQuery); }); </script> <?php } add_action('wp_footer', 'custom_script_pa_autore_and_pa_curatore');
and use this css:
.pa-autore > .autore-label:after { content: ": " } .pa-curatore > .curatore-label:after { content: ": " }
Best regards,
MikeFebruary 17, 2023 at 2:46 pm #1398353Hi Mike,
I just realized now that the two attributes appear only if the “Product short description” field contains text.
On the other hand, if the “Product short description” field does not contain text, the two attributes do not appear :(Best regards
OrianoFebruary 17, 2023 at 7:22 pm #1398389Hi,
It seems that the div woocommerce-product-details__short-description is not present if the “Product short description” field is empty, do you plan on having products without a description?
If you do expect the final site to have products without a description please choose a location that will be uniform for all products such as before/after the in-stock div (Disponibile), assuming this will be present on all products.
I guess you could also choose after the title or price since they should always be present, please ask your client what they would prefer.
If you want to test different locations you only need to change the appendTo class in the script in two places to the new class you want to target:
Best regards,
MikeFebruary 18, 2023 at 11:30 am #1398411Hi Mike
I’m trying to put attributes under the title.
Seems like the best solution, although I haven’t found the good formatting solution, as sometimes a book has only the author, sometimes only the publisher, and sometimes both :(
Perhaps, via the function, one could assign a DIV that contains the two attributes? Would this allow better control of the formatting of the Attributes area? But I wouldn’t know how to do it.Best regards
OrianoFebruary 18, 2023 at 1:03 pm #1398431Hi,
Instead of using .appendTo(‘.single-product-summary .product_title’) try using .insertAfter(‘.single-product-summary .product_title’) this will add the Author & Curatore after the title instead of adding the Author & Curatore to the title. For example:function add_autore_and_curatore_attributes_after_title() { ?> <script> window.addEventListener('DOMContentLoaded', function() { (function($){ $('.shop_attributes .woocommerce-product-attributes-item--attribute_pa_autore').each(function() { $(this).clone().wrapInner('<p class="pa-autore"/>').children(0).unwrap().insertAfter('.single-product-summary .product_title').css({'margin':'0'}); $('.pa-autore .woocommerce-product-attributes-item__label').wrapInner('<p class="autore-label"/>').children(0).unwrap().css({'display':'inline-block','margin':'0'}); $('.pa-autore .woocommerce-product-attributes-item__value').wrapInner('<p class="autore-value"/>').children(0).unwrap().css({'display':'inline-block','margin':'0'}); $('.pa-autore .autore-value p').css({'margin':'0'}); }); $('.shop_attributes .woocommerce-product-attributes-item--attribute_pa_curatore').each(function() { $(this).clone().wrapInner('<p class="pa-curatore"/>').children(0).unwrap().insertAfter('.single-product-summary .product_title').css({'margin':'0'}); $('.pa-curatore .woocommerce-product-attributes-item__label').wrapInner('<p class="curatore-label"/>').children(0).unwrap().css({'display':'inline-block','margin':'0'}); $('.pa-curatore .woocommerce-product-attributes-item__value').wrapInner('<p class="curatore-value"/>').children(0).unwrap().css({'display':'inline-block','margin':'0'}); $('.pa-curatore .curatore-value p').css({'margin':'0'}); }); })(jQuery); }); </script> <?php } add_action('wp_footer', 'add_autore_and_curatore_attributes_after_title');
I tested on the pages linked below and works with:
Author & Curatore no product info
Author & Curatore with product info
Curatore only
Author only
Best regards,
MikeFebruary 18, 2023 at 3:31 pm #1398441Hi Mike,
Your latest version of the function seems to me to work correctly.
The only correction needed is the order of appearance of the two Attributes, which in the frontend must be: Titolo/Autore/Contributore (while now it’s Title/Contributor/Author).I reversed the order of the two attributes in the function, as you see below. Does this seem correct to you?
function add_autore_and_curatore_attributes_after_title() { ?> <script> window.addEventListener('DOMContentLoaded', function() { (function($){ $('.shop_attributes .woocommerce-product-attributes-item--attribute_pa_curatore').each(function() { $(this).clone().wrapInner('<p class="pa-curatore"/>').children(0).unwrap().insertAfter('.single-product-summary .product_title').css({'margin':'0'}); $('.pa-curatore .woocommerce-product-attributes-item__label').wrapInner('<p class="curatore-label"/>').children(0).unwrap().css({'display':'inline-block','margin':'0'}); $('.pa-curatore .woocommerce-product-attributes-item__value').wrapInner('<p class="curatore-value"/>').children(0).unwrap().css({'display':'inline-block','margin':'0'}); $('.pa-curatore .curatore-value p').css({'margin':'0'}); }); $('.shop_attributes .woocommerce-product-attributes-item--attribute_pa_autore').each(function() { $(this).clone().wrapInner('<p class="pa-autore"/>').children(0).unwrap().insertAfter('.single-product-summary .product_title').css({'margin':'0'}); $('.pa-autore .woocommerce-product-attributes-item__label').wrapInner('<p class="autore-label"/>').children(0).unwrap().css({'display':'inline-block','margin':'0'}); $('.pa-autore .woocommerce-product-attributes-item__value').wrapInner('<p class="autore-value"/>').children(0).unwrap().css({'display':'inline-block','margin':'0'}); $('.pa-autore .autore-value p').css({'margin':'0'}); }); })(jQuery); }); </script> <?php } add_action('wp_footer', 'add_autore_and_curatore_attributes_after_title');
February 18, 2023 at 3:38 pm #1398446February 18, 2023 at 3:42 pm #1398447Hi Mike,
thank you so much for your help and explanations.I hope our exchanges can be useful to other Enfold users.
Best regards,
OrianoEnfold x ever
February 18, 2023 at 4:31 pm #1398451Hi,
Glad we were able to help, if you have any further questions please create a new thread and we will gladly try to help you. Thank you for using Enfold.Best regards,
Mike -
AuthorPosts
- The topic ‘Change Shop’ is closed to new replies.