Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi,

    Not sure I understand your question right, if you mean how to use hook, try like this

    add_action( 'woocommerce_after_shop_loop_item_title', 'my_custom_data', 11 );
    
    function my_custom_data() {
    echo 'Some data here';
    }
    Thread Starter Watta21

    (@watta21)

    Thank you for the quick answer. It’s not exactly what I’m looking for.

    Inside the function my_costum_data in your solution, i need to receive a specific product detail.

    What I mean is, you can set a self defined property for every product you want to sell. In my case I want to define a property called start_date where I will set a date. This date should be shown right after the title. How can i get this data inside the loop?

    I assume start_date as product custom field .you can display it this way

    add_action( 'woocommerce_after_shop_loop_item_title', 'my_custom_data', 11 );
    
    function my_custom_data() {
    echo get_post_custom_values( 'start_date' );
    }
    Thread Starter Watta21

    (@watta21)

    Thank you for the answer. It sounds like the solution I am looking for. I’ll try that tomorrow and see if this works.

    Thread Starter Watta21

    (@watta21)

    Hey @phppoet your solution probably only works for wordpress costum field.

    I was looking for a solution to display the woocommerce costum field which are different from wordpress in the way they are referenced.

    I actually found a solution:

    <p>
    <?php
     /**
     * Display the costum field.
     */
     $costumfieldvalues = get_the_terms( $product->id, 'pa_costumfield');
    
     foreach ( $costumfieldvalues as $costumfieldvalue ) {
       echo $costumfieldvalue->name;
     }
    ?></p>

    Replace ‘costumfield’ with the name you set in woocommerce property option e.g. start_date. The specific reference of woocommerce attributes is ‘pa_<costum_field>’.

    Edit: Of course you need to set global $product somewhere in the *.php file you are actually working with.

    Found this solution here:

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Additional information in product preview’ is closed to new replies.