簡體   English   中英

如何讓“添加到購物車按鈕”出現在我放置的位置

[英]How to get 'add to cart button' to appear where I place it

我現在有這段代碼,它在我的 woocommerce 網站上的“添加到購物車”按鈕之后添加了一個按鈕。 這是我在網上找到的一段代碼。

add_action( 'woocommerce_after_add_to_cart_button', 'additional_simple_add_to_cart_10', 20 );
function additional_simple_add_to_cart_10() {
    global $product;

// Only for variable product type 
    $href = '?add-to-cart=' . esc_attr( $product->get_id() ) . '&quantity=10';
    $class = 'ingle_add_to_cart_button-10 button alt';
    $style = 'display: inline-block; margin-top: 12px;';
    $button_text = __( "10 Tickets", "woocommerce" );

    // Output
    echo '<br><a rel="no-follow" href="'.$href.'" class="'.$class.'" style="'.$style.'">'.$button_text.'</a>';

}

我想編輯它,以便按鈕移動到我在頁面上放置此代碼的任何位置,只需要一個通用按鈕,將 10 個單位添加到購物車 - 因為它目前會在添加到購物車后自動放置。

您可以使用 WordPress 中的短代碼 function 為您的 function additional_simple_add_to_cart_10 創建一個短代碼。 這是示例:

add_shortcode('add-to-cart', 'additional_simple_add_to_cart_10');

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM