Viewing 23 posts - 1 through 23 (of 23 total)
  • Author
    Posts
  • #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
    Oriano

    #1397644

    Hey Oriano,
    Please link to the page in question.

    Best regards,
    Mike

    #1397659

    Hi 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
    Oriano

    #1397663

    Hi,
    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,
    Mike

    #1397732

    Hi 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,
    Oriano

    #1397911

    Hi,
    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”
    Enfold_Support_354.jpeg
    This will name the attribute pa_authors so we can call it.
    Then on the product page add the “value” for the attribute:
    Enfold_Support_356.jpeg
    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:
    Enfold_Support_359.jpeg

    Best regards,
    Mike

    #1398184

    Hi 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:
    Screenshot-2023-02-16-at-09.29.11.png

    It can be done? 😳

    Best regards
    Oriano

    #1398205

    Hi,
    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:
    Enfold_Support_369.jpeg

    Best regards,
    Mike

    #1398209

    Hi 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 Surname

    Post scriptum: I hope this will also be useful for an upcoming demo of Enfold “Bookshop”

    Best regards
    Oriano

    #1398256

    Hi,
    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,
    Mike

    #1398315

    Hi 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,
    Oriano

    Enfold x ever

    #1398325

    Hi Mike
    I’m still here…

    Would it be possible to add a second Attribute?
    Example add also the attribute Curator?

    Best regards
    Oriano

    #1398328

    Hi,
    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,
    Mike

    #1398329

    Hi Mike
    the second attribute is “Curatore”.
    See Private content for test url.

    Best regards
    Oriano

    #1398346

    Hi,
    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: ": "
    }

    for this result:
    Enfold_Support_379.jpeg

    Best regards,
    Mike

    #1398353

    Hi 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
    Oriano

    #1398389

    Hi,
    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:
    Enfold_Support_381.jpeg

    Best regards,
    Mike

    #1398411

    Hi 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
    Oriano

    #1398431

    Hi,
    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

    Enfold_Support_383.jpeg

    Best regards,
    Mike

    #1398441

    Hi 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');
    #1398446

    Hi,
    This looks correct and it works in my test.

    Best regards,
    Mike

    #1398447

    Hi Mike,
    thank you so much for your help and explanations.

    I hope our exchanges can be useful to other Enfold users.

    Best regards,
    Oriano

    Enfold x ever

    #1398451

    Hi,
    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

Viewing 23 posts - 1 through 23 (of 23 total)
  • The topic ‘Change Shop’ is closed to new replies.