Avoid initing star ratings multiple times when there are more than one Review forms on the page
#28,540 创建于 2020年12月10日
仓库指标
- 星标
- (10,294 个星标)
- PR 合并指标
- (平均合并 9天 12小时) (30 天内合并 423 个 PR)
描述
Is your feature request related to a problem? Please describe. Hello,
I want to add WooCommerce Tabs (Description, Additional Information, Reviews) and WooCommerce Reviews form on the same page. The problem is that first Reviews form is inited twice and second is not inited at all, screenshot: https://prnt.sc/vzoa98
Describe the solution you'd like
It seems that problem comes from this line and that simply replacing $( '#rating' ) with $( this ) will fix the issue.
I am aware that there shouldn't be multiple elements with same ID, but still this small change would fix the issue and allow more flexible page layouts.
Describe alternatives you've considered
I tried to remove on event handler from my JavaScript code after first init event is fired, but this method is not reliable as it depends on timing when Reviews form is inited and it will also solve only half of the problem - first Reviews form being inited twice while second form would still need to be inited separately.