Okay
  Public Ticket #2539994
Author value in a product (book)
Closed

Comments

  • Remy started the conversation

    I recently purchased the Aurum theme to build an online library.

    I love the theme but I need an “author” value attached to the product. I need to be able to put it in Woo Commerce attributes see ACF, but is there a few things planned to make it appear in the product page?

    Best regard

  • [deleted] replied

    Hi Remy,

    To add an author attribute for products you can use WooCommerce Product Attributes here:

    medium
    (view large image)

    So after you create and assign authors I can give you the code snippet to place the author where you want, simply tell me the placement.

  • Remy replied

    Hello Arlind

    Thanks for the solution

    I need the author's name in these 3 locations (certainly in the invoice descriptions unfortunately, I'm moving too slowly to say where exactly, (this is my first WP work)).

    Thank a lot!

  •   Remy replied privately
  •   [deleted] replied privately
  •   Remy replied privately
  • [deleted] replied

    Hi Remy,

    I have added this code snippet in functions.php of the theme (child theme):

    // titre_serie
    add_action( 'aurum_before_shop_loop_item_title', function() {
        global $product;
        $atts = $product->get_attributes();
        $titre_serie = array_key_exists( 'pa_titre_serie', $atts ) ? $atts['pa_titre_serie'] : null;
        
        if ( $titre_serie ) {
            $terms = [];
            
            foreach ( $titre_serie->get_terms() as $term ) {
                $terms[] = $term->name;
            }
            
            echo sprintf( '<div class="pa-titre-serie">%1$s</div>', implode( ', ', $terms ) );
        }
    } );
    // auteur
    add_action( 'woocommerce_after_shop_loop_item', function() {
        global $product;
        $atts = $product->get_attributes();
        $auteur = array_key_exists( 'pa_auteur', $atts ) ? $atts['pa_auteur'] : null;
        
        if ( $auteur ) {
            $terms = [];
            
            foreach ( $auteur->get_terms() as $term ) {
                $terms[] = sprintf( '<a href="%2$s">%1$s</a>', $term->name, get_term_link( $term ) );
            }
            
            echo sprintf( '<div class="pa-auteur">%1$s</div>', implode( ', ', $terms ) );
        }
        
    } );
    
    So it adds the the attributes below the product as you mentioned:

    medium
    (view large image)

    They are wrapped in DIV container with their respective class names and you can style them with CSS:

    medium
    (view large image)

    The "titre" and "author" comes out only if it exists. Since you havent added "titre" attribute to any of the product I added it for example to "Harry Potter et l’ordre du phénix" product.

    So as you can see if appears only if its assigned.

    I hope you like it.

  •  2
    RemyMayeuxThemeForest replied

    I like your magic !

    Thank a lot.

    R.

  • [deleted] replied

    Hi Remy,

    Happy to hear that my solution workedsmile.png

    Have a nice day!

    P.S: If you like the theme, it would help us a lot if you could give us a five-star rating on Themeforest from your Downloads tab.

    A huge thank you from me and Laborator in advance.

  •  2
    RemyMayeuxThemeForest replied

    Some news.

    My exam is passed, with a mention on the quality of the chosen theme (Aurum).
    Good job!
    Best regard.