Skip to content

Instantly share code, notes, and snippets.

@lawkwok
Created August 3, 2016 22:37
Show Gist options
  • Save lawkwok/413483cf52eb961b08ad97731c1bd0a7 to your computer and use it in GitHub Desktop.
Save lawkwok/413483cf52eb961b08ad97731c1bd0a7 to your computer and use it in GitHub Desktop.
WooCommerce - Smooth scrolls to the review tab and makes it active
<?php
add_action( 'woocommerce_after_single_product', 'activate_review_tab' );
function activate_review_tab() {
echo '<script>
jQuery(document).ready(function ($) {
$("#add_review").click(function(){
var currentTab = $(this).attr("href");
$(".woocommerce-tabs .panel").hide();
$(".woocommerce-tabs li").removeClass("active");
$(currentTab).show();
$("html, body").animate({
scrollTop: $(".woocommerce-tabs").offset().top
}, 1000);
return false;
});
});
</script>';
}
// Add code to your-child-theme/woocommerce/single-product/rating.php
echo '<a id="add_review" href="#tab-reviews">Add a review</a>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment