• Hi Guys,

    I would like to exclude the comment_form() on my WooCommerce product page from cache. So i’ve been trying to use mfunc and load the comment_form() from a function in functions.php.

    See below the mfunc with the function:

    <!-- mfunc mycode -->						
    show_comment_form();
    <!-- /mfunc mycode -->

    And here the function in functions.php:

    function show_comment_form(){
                            $comment_form = array(
                                'title_reply'          => __( 'Ask a question', 'surfsnb' ),
                                'title_reply_to'       => __( 'Leave a Reply to %s', 'woocommerce' ),
                                'comment_notes_after'  => __("PLEASE NOTE: It's not allowed to post any contact details in a question or in a reply to a question!","surfsnb"),
                                'fields'               => array(
                                    'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name', 'woocommerce' ) . ' <span class="required">*</span></label> ' .
                                                '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30" aria-required="true" required /></p>',
                                    'email'  => '<p class="comment-form-email"><label for="email">' . __( 'Email', 'woocommerce' ) . ' <span class="required">*</span></label> ' .
                                                '<input id="email" name="email" type="email" value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30" aria-required="true" required /></p>',
                                ),
                                'label_submit'  => __( 'Submit', 'woocommerce' ),
                                'logged_in_as'  => '',
                                'comment_field' => ''
                            );
                            
                            if ( $account_page_url = wc_get_page_permalink( 'myaccount' ) ) {
    
    $comment_form['must_log_in'] = '<p class="must-log-in">' .  sprintf( __( 'You must be <a href="%s">logged in</a> to post a question.', 'woocommerce' ), esc_url( $account_page_url ) ) . '</p>';
                            }				           
    $comment_form['comment_field'] .= '<p class="comment-form-comment"><label for="comment">' . __( 'Your Message', 'woocommerce' ) . ' <span class="required">*</span></label><textarea id="comment" name="comment" cols="45" rows="8" aria-required="true" required></textarea></p>';
    						
    comment_form( apply_filters( 'woocommerce_product_review_comment_form_args', $comment_form ) );
    }

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • I think fragment cache now only for paid user? check on extension, you’ll see.

    Thread Starter dannykater

    (@dannykater)

    Yeah true, but i’ve got the paid version! Got fragment caching working already in the header. Just not with the comments..

    Hmm…

    1. Ask WP Edge if you can use fragment cache on 2 locations

    2. Disable your header fragment cache, check if your comments fragment cache works.

    Thread Starter dannykater

    (@dannykater)

    @muchmuch11,

    1) Thanks for your answer, i’ve used fragment cache on 2 locations already.

    2) Did that, no difference.

    It seems like the post_id can’t be retrieved anymore from the cached page. That’s why the comment_form is not showing up after the page is cached.

    Any idea how to get the post ID in a function from a cached page?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Exclude comment_form from cache with mfunc (fragment caching)’ is closed to new replies.