admin管理员组

文章数量:1425176

Trying to add the reviews on a site below the add to cart button in woocommerce. Both these snippets of code do it:

add_action('woocommerce_after_add_to_cart_button', create_function( '$args', 'call_user_func(\'comments_template\');'), 14);

function woocommerce_template_product_reviews() {
    woocommerce_get_template( 'single-product-reviews.php' );
}
add_action( 'woocommerce_after_add_to_cart_button', 'comments_template', 50 );

The add to cart will now not work unless you complete a review.

Is there a way to do this with hooks?

Or will I need to use jQuery to clone and move the review code to where I want it.

Trying to add the reviews on a site below the add to cart button in woocommerce. Both these snippets of code do it:

add_action('woocommerce_after_add_to_cart_button', create_function( '$args', 'call_user_func(\'comments_template\');'), 14);

function woocommerce_template_product_reviews() {
    woocommerce_get_template( 'single-product-reviews.php' );
}
add_action( 'woocommerce_after_add_to_cart_button', 'comments_template', 50 );

The add to cart will now not work unless you complete a review.

Is there a way to do this with hooks?

Or will I need to use jQuery to clone and move the review code to where I want it.

Share Improve this question asked Jun 25, 2019 at 9:14 Owen RichardsOwen Richards 132 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

woocommerce_after_add_to_cart_button is inside the <form> element for adding items to the cart, but the reviews form is its own form, and you can't have one form inside another form.

You need to pick a hook that's not inside a <form> element. woocommerce_after_add_to_cart_form seems to be the closest that's still outside a form.

本文标签: jqueryWoocommerce Moving Review Below add to cart breaks button