【问题标题】:How to add "show details" button near the cart button in Woocommerce如何在 Woocommerce 中的购物车按钮附近添加“显示详细信息”按钮
【发布时间】:2018-06-05 11:06:24
【问题描述】:

我想在 woocommerce 单品中添加额外的按钮。我需要在哪个文件中进行更改?

屏幕示例: enter image description here

【问题讨论】:

标签: wordpress button woocommerce add woocommerce-theming


【解决方案1】:

试试这个代码,

function wc_shop_demo_button() {
    echo '<a class="button demo_button" style="padding-right: 0.75em;padding-left: 0.75em;margin-left: 8px; background-color: #0ebc30;" href="'.get_field( "url_demo" ).'" target="_blank">Show Details</a>';
}
add_action( 'woocommerce_after_shop_loop_item', 'wc_shop_demo_button', 20 );
add_action( 'woocommerce_after_add_to_cart_button', 'wc_shop_demo_button', 20 );

希望这会对您有所帮助。欲了解更多详情,请访问,

how to add button after woocommerce shop loop item

【讨论】:

    【解决方案2】:

    首先,使用高级自定义字段插件为 Woocommerce 产品页面创建一个自定义字段。

    关于使用 ACF 插件创建自定义字段,请参阅以下文章。

    https://wpmayor.com/woocommerce-custom-fields-how-to-create-and-display-them/

    要在网站前端显示自定义按钮,请在functions.php文件中添加以下代码。

    function rf_custom_product_button() {
        echo '<a class="button custom_button" href="'.get_field( "custom_button" ).'" target="_blank">Click Here</a>';
    }
    add_action( 'woocommerce_after_add_to_cart_button', 'rf_custom_product_button', 20 );
    add_action( 'woocommerce_after_shop_loop_item', 'rf_custom_product_button', 20 );
    

    在上述代码中,将“custom_button”更改为您使用 ACF 创建的字段的名称。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-30
      • 2018-04-12
      • 2012-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多