首页 文章

当有人将鼠标悬停在产品上时,自定义我的wordpress网站以显示添加到购物车按钮 . 我附上了碎石

提问于
浏览
0

我对wordpress,woocommerce和elementor有非常初级的理解 . 我还在学习很多东西 . 我相信最好的学习方法就是模仿 . 所以,我经历了各种主题,并尝试使用Elementor模仿他们的行为和外观 . 但是,这个特别的主题引起了我的注意 . 当有人将鼠标悬停在产品图片上而不是始终在那里时,会出现“添加到购物车”按钮 . 你能帮我解决这个问题,或者至少指出我正确的方向吗?

This is how it should look when someone hovers over the images

This is how it looks when the mouse pointer is away

1 回答

  • 0
    <a href="<?php the_permalink(); ?>" class="more">More info</a><?php
    if($available){?><a href="<?php
                    $add_to_cart = do_shortcode('[add_to_cart_url id="'.$post->ID.'"]');
                    echo $add_to_cart;
    ?>" class="more">Buy now</a>
                        <?php 
                    }
    

    此代码按预期解决了我的问题 .

    WooCommerce documentation reference

    • 解决方案:在主题的function.php文件中添加代码 .

    add_action('woocommerce_single_product_summary','my_extra_button_on_product_page',30);

    function my_extra_button_on_product_page(){global $ product; echo'加入购物车'; }

    • 解决方案:安装自定义WooCommerce添加到购物车插件

    Custom WooCommerce Add to Cart Plugin

    • 解决方案:您可以使用带有短代码的挂钩:

    custom add to cart button

    或者在您自己的模板中为WooCommerce文件创建覆盖

相关问题