I want to get woocommerce reviews by product id and display it in a template

后端 未结 8 1664
谎友^
谎友^ 2020-12-18 02:04

I want to fetch woocommerce product reviews by product id or anything else and want to display it in a template created by me.

8条回答
  •  [愿得一人]
    2020-12-18 02:43

    In woocommerce/templates/single-product/tabs/tabs.php

    If you run a print_r() on $tabs after it has been declared you'll see that a portion of the output is the following:

    [reviews] => Array (
        [title] => Reviews (3)
        [priority] => 30
        [callback] => comments_template
    )
    

    This means that the callback is the function: comments_template().

    Since this function doesn't accept a $post_id parameter, the would need to be called within the loop.

    However, the function does accept a parameter of the template file to use, so to answer the OP's direct question of how to use a custom template file - you can use the function like so:

    comments_template( string $file = '/comments.php', bool $separate_comments = false );
    

    This ^ was taken directly from the codex

提交回复
热议问题