如何在“添加到购物车”按钮(WordPress / Woocommerce)之前添加“立即购买”按钮[关闭]

问题描述 投票:0回答:2

我想添加一个"Buy Now"按钮BEFORE"Add to cart"按钮。我已经尝试过其他解决方案,但它们都是按钮after"Add Cart"按钮。

例:

Example

php wordpress woocommerce
2个回答
0
投票

你可以使用woocommerce_before_add_to_cart_quantity钩如下

add_action( 'woocommerce_after_add_to_cart_quantity', 'by_now' );

function by_now() {

    echo '<div class="test"> buy now </div>';
}

在你的CSS中添加:

.test {
display: inline-block;
 }
.woocommerce div.product form.cart .button {
vertical-align: middle;
float: none !important ;
}

产量

enter image description here

您网站的输出

enter image description here你需要将代码放在functions.php


0
投票

你可以使用hook "Buy Now"添加before woocommerce_before_add_to_cart_button

add_action( 'woocommerce_before_add_to_cart_button', 'custom_content_before_addtocart_button', 100 );
function custom_content_before_addtocart_button() {
    // custom content.
    echo 'Buy Now';
}

enter image description here

你可以使用hook "Buy Now"添加after woocommerce_after_add_to_cart_button

add_action( 'woocommerce_after_add_to_cart_button', 'custom_content_after_addtocart_button', 100 );
function custom_content_after_addtocart_button() {
    // custom content.
    echo 'Buy Now';
}
© www.soinside.com 2019 - 2024. All rights reserved.