简体   繁体   English

woocommerce 添加js到产品描述

[英]woocommerce adding js to product description

I have been asked to add a short JavaScript script to the short description of every product description on a WooCommerce site.我被要求在 WooCommerce 站点上的每个产品描述的简短描述中添加一个简短的 JavaScript 脚本。 It is actually an image with a simple "onclick" that scrolls smoothly to another part of the page, depending on different conditions.它实际上是一个带有简单“onclick”的图像,可以根据不同的条件平滑地滚动到页面的另一部分。 It has been added to every product via a PHP script directly to the MySQL DB.它已通过 PHP 脚本直接添加到 MySQL 数据库中的每个产品中。 It works fine, but the only problem is that, when editing a product in the woo admin, the "onclick" part is automatically removed from the short description when saving the modifications, even when the short description hasn't been modified.它工作正常,但唯一的问题是,当在 woo admin 中编辑产品时,“onclick”部分会在保存修改时自动从简短描述中删除,即使简短描述没有被修改。

I am not familiar with WooCommerce nor with shortcodes nor with the best ways to use JavaScript in this environment.我不熟悉 WooCommerce,也不熟悉短代码,也不熟悉在此环境中使用 JavaScript 的最佳方法。

So my question: is there a way to prevent the "onclick" part to be removed when saving changes, and if not, what is the best way to achieve the insertion of JavaScript inside a product short description, and keep it untouched when a product is edited?所以我的问题是:有没有一种方法可以防止在保存更改时删除“onclick”部分,如果没有,在产品简短描述中插入 JavaScript 并在产品时保持不变的最佳方法是什么被编辑?

Thanks in advance.提前致谢。

Here is an example of how you can do this.这是您如何执行此操作的示例。 You should add your script below code and add it in your theme functions.php .您应该在代码下方添加脚本并将其添加到主题functions.php中。 Your question is kinda unclear please share your code so we can understand your code and write the answer correctly.您的问题有点不清楚,请分享您的代码,以便我们理解您的代码并正确编写答案。

function firefog_add_script_short_descr(){
  ?>
  <script>
    jQuery(document).ready(function($) {
     
     <!-- Your jquery code goes here-->
     
    })
  </script>
<?php  
}
add_filter('woocommerce_before_add_to_cart_form','firefog_add_script_short_descr');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM