• Resolved jrothra

    (@jrothra)


    URL: https://www.johnrothra.com/store/church-growth/1x-evangelism-kingdom-growth-strategy-local-church/

    I’m wanting to add the name of the author(s) underneath the item description. However, what I’ve tried isn’t working. So here I post.

    What I Tried
    I added the custom field product_author under the item’s custom field box, and entered the name of the author (me), clicked update under the new custom field just to be sure, then clicked to update the entire product listing.

    I then copied the title.php file from plugins/woocommerce/templates/single-product/ to theme_child/woocommerce/templates/single-product/. After this, I edited the copied file by adding an H3 under the title as so:

    <h1 itemprop="name" class="product_title entry-title"><?php the_title(); ?></h1>
    <h3 class="product_author"><?php echo get_post_meta($post->ID, 'product_author', TRUE); ?></h3>

    I then cleared all caches and refreshed the page, but the author did not display. I tried altering where I put the copied file by placing it in the following locations, but none worked:

    • theme_child/woocommerce/templates/
    • theme_child/woocommerce

    What did I do wrong or miss?

    https://www.ads-software.com/plugins/woocommerce/

Viewing 31 replies (of 31 total)
  • Thread Starter jrothra

    (@jrothra)

    Lorro (or whomever):

    The problem is resolved, however, I want to tweak something in the code you offered. In the title.php I have this code:

    <?php
    global $product;
      $attributes = $product->get_attributes();
      foreach ($attributes as $attribute) {
        if ($attribute["name"] == "Author") {
          $values = array_map( 'trim', explode( WC_DELIMITER, $attribute['value'] ) );
          echo 'Author: ';
    	  echo apply_filters( 'woocommerce_attribute', wpautop( wptexturize( implode( ', ', $values ) ) ), $attribute, $values );
        }
      }
    ?>

    What I want to do is change echoed “Author: Dory I. Lost” from standard body text to an H4. To do this I figure it’s a matter of simply adding the opening and closing H* tags in the PHP. The opening is easy, but after multiple tries, I can’t figure out where to put the closing tag.

    Here’s my opening:

    echo '<h4>Author: ';

    But where in here does the closing go:

    echo apply_filters( 'woocommerce_attribute', wpautop( wptexturize( implode( ', ', $values ) ) ), $attribute, $values );

Viewing 31 replies (of 31 total)
  • The topic ‘Adding Product Author’ is closed to new replies.