有人知道如何将JavaScript添加到所有WooCommerce产品中吗?根据我所读的内容,我可能需要将代码上传到我的服务器上。然后通过函数指向它?
将JavaScript添加到所有WooCommerce产品
1 个回复
最合适的回答,由SO网友:Self Designs 整理而成
如果需要在单个产品页面上执行此操作,请使用此条件,然后将JavaScript文件排队。
function enqueue_single_product_javascript()
{
if(is_product())
{
// Use wp_enqueue_script()
}
}
add_action(\'wp_enqueue_scripts\', \'enqueue_single_product_javascript\');
https://developer.wordpress.org/reference/functions/wp_enqueue_script/https://docs.woocommerce.com/document/conditional-tags/