Created
August 3, 2016 22:37
-
-
Save lawkwok/413483cf52eb961b08ad97731c1bd0a7 to your computer and use it in GitHub Desktop.
WooCommerce - Smooth scrolls to the review tab and makes it active
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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>'; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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