希望你一切顺利,我需要我的woo商务网站的帮助。我希望当有人将产品添加到购物车中时,颜色会立即更改为另一种。
这可以用一些简单的Javascript完成,然后制作一个PHP函数并将其添加到wordpress网站。如果你知道函数在哪里,你可以将函数添加到functions.php文件中,如果不是,只需通过WordPress Dashboard安装一个代码段插件即可。
这是一种方法:
-
安装Snippets插件(示例:https://wordpress.org/plugins/code-snippets/)
-
创建一个类似的函数(如果需要,进行必要的更改,但很可能开箱即用(
add_action( 'wp_footer', 'single_add_to_cart_event_text_replacement' ); function single_add_to_cart_event_text_replacement() { global $product; if( ! is_product() ) return; // Only single product pages ?> <script type="text/javascript"> (function($){ // You can change the “button.*******” to your css element if it does not work $('button.single_add_to_cart_button').click( function(){ // Change the Red to your desired color name or HEX Value (Example: #000000 is black) $(this).css('background-color','red'); }); })(jQuery); </script> <?php
}
-
最后保存并激活
-
转到您的单一产品页面并单击添加到购物车:(