久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

刪除 WooCommerce 3 中特定產品類別的添加到購物車

Remove add to cart button for specific product categories in WooCommerce 3(刪除 WooCommerce 3 中特定產品類別的添加到購物車按鈕)
本文介紹了刪除 WooCommerce 3 中特定產品類別的添加到購物車按鈕的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我需要為定義的產品類別的產品隱藏添加到購物車"按鈕.

我希望確定的數量仍然可見,因為我正在使用 Yith 請求報價插件,該插件使用報價系統的數量.

目標:為保留數量字段的特定產品類別隱藏添加到購物車"按鈕.

我正在尋找一小段代碼放在我的 functions.php 文件中.

解決方案

更新:(在簡單產品中添加了 WooCommerce 產品插件插件的兼容性).

這里是(對于定義的簡單和可變產品類型的產品類別)的方法:

  • 可選,在檔案頁面上:將添加到購物車的按鈕替換為產品的鏈接按鈕.
  • 在單個產品頁面上:刪除添加到購物車按鈕(保留數量字段)

代碼:

//無按鈕加回數量功能(可變產品)函數 add_back_quantities_variable_products(){全球$產品;?><div class="woocommerce-variation-add-to-cart changes_button"><?phpdo_action('woocommerce_before_add_to_cart_quantity');woocommerce_quantity_input(數組('min_value' =>apply_filters('woocommerce_quantity_input_min', $product->get_min_purchase_quantity(), $product ),'max_value' =>apply_filters('woocommerce_quantity_input_max', $product->get_max_purchase_quantity(), $product),'輸入值' =>isset( $_POST['quantity'] ) ?wc_stock_amount( $_POST['quantity'] ) : $product->get_min_purchase_quantity(),) );do_action('woocommerce_after_add_to_cart_quantity');?><input type="hidden" name="add-to-cart" value="<?php echo absint( $product->get_id() ); ?>"/><input type="hidden" name="product_id" value="<?php echo absint( $product->get_id() ); ?>"/><input type="hidden" name="variation_id" class="variation_id" value="0"/>

<?php}//沒有按鈕的功能加回數量(簡單產品)函數 add_back_quantities_simple_products(){全球$產品;如果(!$product->is_purchasable())返回;回聲 wc_get_stock_html( $product );如果 ( $product->is_in_stock() ) : ?><?php do_action('woocommerce_before_add_to_cart_form');?><form class="cart" method="post" enctype='multipart/form-data'><?php//對于 WooCommerce 產品附加組件(更新)do_action('woocommerce_before_add_to_cart_button');do_action('woocommerce_before_add_to_cart_quantity');woocommerce_quantity_input(數組('min_value' =>apply_filters('woocommerce_quantity_input_min', $product->get_min_purchase_quantity(), $product ),'max_value' =>apply_filters('woocommerce_quantity_input_max', $product->get_max_purchase_quantity(), $product),'輸入值' =>isset( $_POST['quantity'] ) ?wc_stock_amount( $_POST['quantity'] ) : $product->get_min_purchase_quantity(),) );do_action('woocommerce_after_add_to_cart_quantity');?></表單><?phpdo_action('woocommerce_after_add_to_cart_form');萬一;}//在單個產品頁面中用您的自定義按鈕替換添加到購物車按鈕和數量add_action('woocommerce_single_product_summary', 'conditionally_replacing_template_single_add_to_cart', 1, 0);函數conditionally_replacing_template_single_add_to_cart() {全球 $product, $post;//在此處設置數組中的產品類別$terms = array('T恤','手套');if( has_term( $terms, 'product_cat' ) ){//對于可變產品類型if($product->is_type('變量')){//刪除添加到購物車按鈕和數量remove_action('woocommerce_single_variation', 'woocommerce_single_variation_add_to_cart_button', 20);//添加不帶按鈕的數量add_action('woocommerce_single_variation', 'add_back_quantities_variable_products', 20);}//對于簡單的產品類型否則 if( $product->is_type( 'simple' ) ){//刪除添加到購物車按鈕和數量remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30);//添加不帶按鈕的數量add_action('woocommerce_single_product_summary', 'add_back_quantities_simple_products', 30);}}}

也可選擇(對于檔案頁面):

//用商店和檔案頁面中的產品鏈接代替添加到購物車的按鈕//對于可變和簡單的產品add_filter('woocommerce_loop_add_to_cart_link', 'replace_loop_add_to_cart_button', 10, 2);函數 replace_loop_add_to_cart_button( $button, $product ) {//在此處設置數組中的產品類別$terms = array('T恤','手套');//僅適用于簡單產品if(!$product->is_type('variable')) 返回;if( has_term( $terms, 'product_cat', $product->get_id() ) ){$button_text = __( "查看產品", "woocommerce");$button = '<a class="button" href="' . $product->get_permalink() .'">'.$button_text .'</a>';}返回 $ 按鈕;}

代碼位于活動子主題(或主題)的 function.php 文件或任何插件文件中.

此代碼已在 WooCommerce 3+ 下測試并有效.

<小時>

對于產品標簽 - 如果您希望它與產品標簽一起使用,您將替換:

if( has_term( $terms, 'product_cat' ) ){

if( has_term( $terms, 'product_tag' ) ){

I need to hide the "add to cart" button for products of a defined product category.

I would like the quantity fied still visible because I am using the Yith request a quote plugin which uses quantities for the quote system.

The goal: hide "add to cart" button for a certain product category keeping the quantities fields.

Im looking for a short string of code to place in my functions.php file.

解決方案

Updated: (Added compatibility for WooCommerce Product Add-ons plugin in simple products).

Here is the way (for defined product categories for simple and variable product types) to:

  • Optionally, On archives pages: Replace add-to-cart buttons by a linked button to the product.
  • On single product pages: Remove add to cart button (keeping quantities fields)

The code:

// function add back quantities without button (variable product)
function add_back_quantities_variable_products(){
    global $product;

    ?>
    <div class="woocommerce-variation-add-to-cart variations_button">
    <?php

    do_action( 'woocommerce_before_add_to_cart_quantity' );

    woocommerce_quantity_input( array(
        'min_value'   => apply_filters( 'woocommerce_quantity_input_min', $product->get_min_purchase_quantity(), $product ),
        'max_value'   => apply_filters( 'woocommerce_quantity_input_max', $product->get_max_purchase_quantity(), $product ),
        'input_value' => isset( $_POST['quantity'] ) ? wc_stock_amount( $_POST['quantity'] ) : $product->get_min_purchase_quantity(),
    ) );

    do_action( 'woocommerce_after_add_to_cart_quantity' );
    ?>
        <input type="hidden" name="add-to-cart" value="<?php echo absint( $product->get_id() ); ?>" />
        <input type="hidden" name="product_id" value="<?php echo absint( $product->get_id() ); ?>" />
        <input type="hidden" name="variation_id" class="variation_id" value="0" />
    </div>
    <?php
}


// function add back quantities without button (simple product)
function add_back_quantities_simple_products(){
    global $product;

    if ( ! $product->is_purchasable() ) return;

    echo wc_get_stock_html( $product );

    if ( $product->is_in_stock() ) : ?>

        <?php do_action( 'woocommerce_before_add_to_cart_form' ); ?>

        <form class="cart" method="post" enctype='multipart/form-data'>
            <?php
                // For WooCommerce Product add-ons (Update)
                do_action( 'woocommerce_before_add_to_cart_button' ); 

                do_action( 'woocommerce_before_add_to_cart_quantity' );

                woocommerce_quantity_input( array(
                    'min_value'   => apply_filters( 'woocommerce_quantity_input_min', $product->get_min_purchase_quantity(), $product ),
                    'max_value'   => apply_filters( 'woocommerce_quantity_input_max', $product->get_max_purchase_quantity(), $product ),
                    'input_value' => isset( $_POST['quantity'] ) ? wc_stock_amount( $_POST['quantity'] ) : $product->get_min_purchase_quantity(),
                ) );

                do_action( 'woocommerce_after_add_to_cart_quantity' );
            ?>
        </form>

    <?php
        do_action( 'woocommerce_after_add_to_cart_form' );
    endif;
}


// Replacing add to cart button and quantities by your custom button in Single product pages
add_action( 'woocommerce_single_product_summary', 'conditionally_replacing_template_single_add_to_cart', 1, 0 );
function conditionally_replacing_template_single_add_to_cart() {
    global $product, $post;

    // Set HERE your product categories in the array
    $terms = array( 't-shirts', 'gloves' );

    if( has_term( $terms, 'product_cat' ) ){

        // For variable product types
        if( $product->is_type( 'variable' ) ){
            // Removing add to cart button and quantities
            remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation_add_to_cart_button', 20 );

            // Add back quantities without button
            add_action( 'woocommerce_single_variation', 'add_back_quantities_variable_products', 20 );
        }
        // For simple product types
        else if( $product->is_type( 'simple' ) )
        {
            // Removing add to cart button and quantities
            remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );

            // Add back quantities without button
            add_action( 'woocommerce_single_product_summary', 'add_back_quantities_simple_products', 30 );
        }
    }
}

And optionally (for archives pages):

// Replacing the button add to cart by a link to the product in Shop and archives pages
// For variable and simple products
add_filter( 'woocommerce_loop_add_to_cart_link', 'replace_loop_add_to_cart_button', 10, 2 );
function replace_loop_add_to_cart_button( $button, $product  ) {
    // Set HERE your product categories in the array
    $terms = array( 't-shirts', 'gloves' );

    // Only for simple products
    if( ! $product->is_type( 'variable' ) ) return;

    if( has_term( $terms, 'product_cat', $product->get_id() ) ){
        $button_text = __( "View product", "woocommerce" );
        $button = '<a class="button" href="' . $product->get_permalink() . '">' . $button_text . '</a>';
    }
    return $button;
}

Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

This code is tested under WooCommerce 3+ and works.


For Product tags - If you want that to work with product tags, you will replace:

if( has_term( $terms, 'product_cat' ) ){

by

if( has_term( $terms, 'product_tag' ) ){

這篇關于刪除 WooCommerce 3 中特定產品類別的添加到購物車按鈕的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Cannot use #39;Object as class name as it is reserved Cake 2.2.x(不能使用 Object 作為類名,因為它是保留的 Cake 2.2.x)
Session is lost after an OAuth redirect(OAuth 重定向后會話丟失)
Pagination Sort in Cakephp 3.x(Cakephp 3.x 中的分頁排序)
CakePHP Shared core for multiple apps(CakePHP 多個應用程序的共享核心)
Login [ Auth-gt;identify() ] always false on CakePHP 3(在 CakePHP 3 上登錄 [ Auth-identify() ] 始終為 false)
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 87 bytes)(致命錯誤:允許的內存大小為 134217728 字節已用盡(嘗試分配 87 字節))
主站蜘蛛池模板: 99在线免费观看视频 | 国产精品久久av | 国产色片| 中文字幕第7页 | 黄色毛片在线看 | 国产91在线播放精品91 | 国产成人小视频 | 中文一区二区 | 精品视频一区二区三区在线观看 | 亚洲91 | 成人国产精品久久久 | 综合色站导航 | www操操| 在线观看av网站永久 | 日日爱视频 | 男人的天堂中文字幕 | 黄色成人在线观看 | 日韩一区二区三区av | 国产福利观看 | 爱爱视频在线观看 | 中文字幕日韩专区 | 成人精品 | 国产精品久久久久久中文字 | 在线观看www | 日韩欧美专区 | 涩涩视频在线观看 | 99久久影院 | 亚洲精品乱码久久久久久久久久 | 日日夜夜狠狠操 | 91偷拍精品一区二区三区 | 在线看免费 | 欧美成人手机视频 | 亚洲第一天堂 | www视频在线观看 | 精品免费国产一区二区三区 | 日韩在线播放网址 | 免费午夜视频在线观看 | 久久成人一区 | 日韩精品一区二区三区在线观看 | 欧美不卡视频一区发布 | 少妇午夜一级艳片欧美精品 |