Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #340911
    Alex
    Participant

    Hi there

    I have set up several book attributes on my site. They show and work as filters on the category page, but do not display on the product page.

    I want to the attributes to display on the product page so readers can use them to find relevant books.

    Fotografie doesn’t have an attributes block pulling from the taxonomy, so do you have any suggestions about how to add this into the product meta section of the single product template without adding custom fields?

    Thanks

    Alex

    #340919
    sujeet
    Keymaster

    Hello Alex,

    I guess to show all the attributes in all the product page to filter to find relevant product, you need to include them in every products. But your message is confusing and unable to help you fixing your issues. Can you please explain sending few screenshots ? Thank you.

    Regards,
    Sujeet

    #340939
    Alex
    Participant

    Hi Sujeet

    I would love to send you screen shots, except you can’t add images to this forum box, and you can’t send more than one link or you’re marked as spam.

    As an example, this is a book product page: https://alexandriablaelock.com/wolf-vs-orb-paperback/. The display is the usual WooCommerce layout with category and tags next to the SKU under the payment options.

    If you click the category, you’re taken to the category page. If you click a tag, it takes you to a page listing other products tagged the same.

    Each book also has attributes for genre, length and format. I’ve ticked the visible on product page, but they’re not visible because Fotographie theme does not include them as an option to add to the template.

    The linked book’s attributes are mystery, novella, and paperback, but if you want to look at the other mysteries, you have to navigate away from the product page to do it.

    The filter works fine.

    Regards

    Alex

     

    #340948
    sujeet
    Keymaster

    Hello Alex,

    Thanks for the response. I will get back to you soon.

    Regards,
    Sujeet

    #340949
    sujeet
    Keymaster

    Hello Alex,

    By default, WooCommerce lets you make attributes visible on the product page, but currently Fotografie theme doesn’t actually output them in the single product template. That’s why you only see Category, Tags, and SKU, but not your custom attributes (genre, length, format).

    They are only visible in Additional Information when you tick the “visible on the product page” option of any product which you already have it in each book. Please check the screenshot.

    additional-information

    Please feel free to reach out if you have any other questions.

    Regards,
    Sujeet

    #340987
    Alex
    Participant

    Thanks for getting back to me Sujeet

    I have custom codes for the attributes. Is there a code solution to get them in the place I want them?

    Or do I need to get something like the ACF plugin?

    Regards

    Alex

    #341004
    sujeet
    Keymaster

    Hello Alex,

    To add custom function or code to the theme, It is better to use child theme instead because once you get your theme updated, your changes in the theme will be erased. So please think that as well while using custom function. Check this link for creating child theme: https://catchthemes.com/blog/create-child-theme-wordpress/

    The following code can show the additional information just after SKU, Category in product page.

    Please got to Dashboard => Tools => Theme File Editor => Function.php

    theme-file

    att

    Here is the code:

    
    add_action('woocommerce_product_meta_end', 'custom_attributes_inline');
    
    function custom_attributes_inline()
    {
        // Paste your custom codes here
        // You will see the attributes under SKU, Category in product page
    }
    

    Please let me know if this worked. Thank you.

    Regards,
    Sujeet

    • This reply was modified 4 weeks, 1 day ago by sujeet.
    • This reply was modified 4 weeks, 1 day ago by sujeet.
    • This reply was modified 4 weeks, 1 day ago by sujeet.
    • This reply was modified 4 weeks, 1 day ago by sujeet.
    • This reply was modified 4 weeks, 1 day ago by sujeet.
    • This reply was modified 4 weeks, 1 day ago by sujeet.
    • This reply was modified 4 weeks, 1 day ago by sujeet.
    • This reply was modified 4 weeks, 1 day ago by sujeet.
    • This reply was modified 4 weeks, 1 day ago by sujeet.
    #341117
    Alex
    Participant

    Thanks for getting back to me Sujeet

    I used the plugin to create a child theme, however I do not see a theme file editor in the tools menu as shown.

    Nonetheless, I pasted the snippet shown above into the functions.php for the child theme which did not change the location of the attributes display.

    The email version included a longer section of code which gave me a critical error.

    The error was syntax error unexpected T_CONSTANT_ENCAPSED_STRING

    The error was on line 48

    $links[] = ‘slug) . ‘” href=”‘ . esc_url($url) . ‘”>’ . esc_html($term->name) . ”; }

     

    On a related note, is there an easy way to transfer my templates from the parent to the child theme? Copying the templates and files folders did not work.

    Regards

    Alex

     

     

     

     

    #341167
    sujeet
    Keymaster

    Hello Alex,

    Try to add the following code instead.

    add_action('woocommerce_product_meta_end', 'su_filterable_attributes_inline');
    
    function su_filterable_attributes_inline()
    {
    if (! function_exists('wc_get_page_permalink')) return;
    
    global $product;
    if (! $product) return;
    
    $attributes = $product->get_attributes();
    if (empty($attributes)) return;
    
    $shop_url = wc_get_page_permalink('shop');
    if (! $shop_url) return;
    
    echo '<span class="custom-product-attributes">';
    
    foreach ($attributes as $attribute) {
    if (! $attribute->get_visible()) continue;
    
    if ($attribute->is_taxonomy()) {
    $taxonomy = $attribute->get_name();
    $label = wc_attribute_label($taxonomy);
    $base_slug = sanitize_title(str_replace('pa_', '', $taxonomy));
    $filter_key = 'filter_' . $base_slug;
    
    $terms = wc_get_product_terms($product->get_id(), $taxonomy, array('fields' => 'all'));
    if (empty($terms)) continue;
    
    $links = array();
    foreach ($terms as $term) {
    $url = add_query_arg(
    array(
    $filter_key => $term->slug,
    'query_type_' . $base_slug => 'or',
    ),
    $shop_url
    );
    $links[] = '<a class="attr-chip attr-chip--' . esc_attr($term->slug) . '" href="' . esc_url($url) . '">' . esc_html($term->name) . '</a>';
    }
    
    echo '<span class="product-attr"><strong>' . esc_html($label) . ':</strong> ' . implode(', ', $links) . '</span> <br>';
    } else {
    
    $label = wc_attribute_label($attribute->get_name());
    $value = implode(', ', $attribute->get_options());
    echo '<span class="product-attr"><strong>' . esc_html($label) . ':</strong> ' . esc_html($value) . '</span> ';
    }
    }
    
    echo '</span>';
    }
    

    And you can try using ‘All-in-One WP Migration and Backup’ plugin to transfter the theme. That may help.

    Please let me know if this worked. Thank you.

    Regards,
    Sujeet

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.