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

隱藏在 Woocommerce 中默認(rèn)選擇具有獨特變體的可變

Hide variable product dropdown that has a unique variation selected by default in Woocommerce(隱藏在 Woocommerce 中默認(rèn)選擇具有獨特變體的可變產(chǎn)品下拉菜單)
本文介紹了隱藏在 Woocommerce 中默認(rèn)選擇具有獨特變體的可變產(chǎn)品下拉菜單的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時送ChatGPT賬號..

我有一個獨特的問題.我正在使用他們無法支持請求的插件.我需要將變體拆分為單獨的項目,但是如果我復(fù)制和粘貼并將它們變成一個簡單的產(chǎn)品,那么我無法同步產(chǎn)品的計數(shù)以跟蹤庫存.作為一種解決方法,我需要能夠禁用不需要的變體,只保留我確實需要的變體.但這是我遇到麻煩的地方.如果我啟用了一個變體,那么我不想顯示下拉列表,而是希望它在 UI 上看起來像一個簡單的產(chǎn)品.我嘗試了一切,但無法讓它工作.

I have a unique issue. I am using a plugin where they are not able to support the request. I need to split out variations into separate items, but if I copy and paste and turn them into a simple product, then I can't sync the count for the product to track inventory stock. As a workaround I needed to be able to disable the variations I do not need, keeping only the one that I do need. But here is where I am having trouble. If I have one variation enabled, then I do not want to show the dropdown, and instead want it to look like a simple product on the UI. I tried everything and cannot get it to work.

我什至嘗試使用

add_filter( 'woocommerce_hide_invisible_variations', '__return_true', 10, 3 );

沒有成功,因為即使計數(shù)為 0、價格為 0 且項目已禁用,它們?nèi)钥梢娗椅措[藏.

with no success as they are visible and not hidden even though the counts are 0, the price is 0, and the item is disabled.

如何顯示沒有下拉菜單的產(chǎn)品頁面?更進一步;我刪除了所有變體,但我需要保留的變體除外.由于同步插件,我需要將其保持在變化模式.如何在不顯示任何下拉列表的情況下顯示它?

How can I show the product page with no drop-down? Take it one step further; I delete all variations except the one that I need to keep. I need to keep it in variations mode due to the plugin that syncs. How do I display it without any dropdowns showing?

示例邏輯:

如果產(chǎn)品類型是變體并且啟用計數(shù) == 1 則特殊 ui 顯示,否則正常.

If product type is a variation and enabled count == 1 then special ui display, else normal.

謝謝.

推薦答案

重要提示:代碼僅適用當(dāng)唯一變體被選擇為默認(rèn)表單值時:

IMPORTANT: The code only works when the unique variation is selected as default form value:

以下代碼將隱藏僅啟用一個變體并默認(rèn)選擇的變量產(chǎn)品、屬性下拉列表和所選變體價格:

The following code will hide from variable products that have only one variation enabled and selected by default, the attribute dropdown and the selected variation price:

add_action( 'woocommerce_before_add_to_cart_form', 'single_unique_variation_ui', 10 );
function single_unique_variation_ui(){
    global $product;

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

    $available_variations = $product->get_available_variations(); // Get available variations
    $default_attributes   = $product->get_default_attributes();   // Get default attributes

    // Only for a unique selected variation by default
    if( ! ( sizeof($available_variations) == 1 && sizeof($default_attributes) == 1 ) )
        return;

    // Get the unique variation
    $variation = reset($available_variations);

    // Loop through
    if( reset($variation['attributes']) == reset($default_attributes) ) :
    // Styles
    ?>
    <style>
        div.woocommerce-variation-price, table.variations { display:none; }
    </style>
    <?php
    endif;
}

代碼位于活動子主題(或活動主題)的 function.php 文件中.經(jīng)測試有效.

Code goes in function.php file of your active child theme (or active theme). Tested and works.

沒有代碼 (正常的woocommerce行為):

使用代碼 (隱藏屬性下拉列表和價格):

它將為您提供與簡單產(chǎn)品相同的用戶界面

It will give you the same UI than simple products

這篇關(guān)于隱藏在 Woocommerce 中默認(rèn)選擇具有獨特變體的可變產(chǎn)品下拉菜單的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Add programmatically a downloadable file to Woocommerce products(以編程方式將可下載文件添加到 Woocommerce 產(chǎn)品)
Get today#39;s total orders count for each product in Woocommerce(獲取今天 Woocommerce 中每種產(chǎn)品的總訂單數(shù))
Add Custom registration fields in WooCommerce and phone field validation issue(在 WooCommerce 和電話字段驗證問題中添加自定義注冊字段)
Add a select field that will change price in Woocommerce simple products(在 Woocommerce 簡單產(chǎn)品中添加一個將更改價格的選擇字段)
Add custom columns to admin products list in WooCommerce 3(在 WooCommerce 3 中將自定義列添加到管理產(chǎn)品列表)
Customizing checkout quot;Place Orderquot; button output html(自定義結(jié)帳“下訂單按鈕輸出html)
主站蜘蛛池模板: 亚洲欧美日本在线 | av先锋资源| av一区二区三区四区 | 欧洲精品一区 | 欧美黄在线观看 | 欧美一区二区三区在线播放 | 久久99精品久久 | 欧美福利视频 | 国产在线视频一区 | 正在播放亚洲 | 欧美久久综合 | 在线免费观看一区二区 | 亚洲精品粉嫩美女一区 | 国产精品成人av | 欧美午夜视频 | 欧美亚洲激情 | 美女拍拍拍网站 | 国产精品久久国产精品99 | 国产一区视频在线 | 成人影视网址 | 日一区二区 | 国产真实乱对白精彩久久小说 | 亚洲精品片 | www.亚洲免费| 亚洲图片视频一区 | 91国产视频在线观看 | 黄片毛片 | 4hu最新网址| 国产一区二区三区在线免费观看 | 特级丰满少妇一级aaaa爱毛片 | 欧美性极品xxxx做受 | www.天天操| 五月花丁香婷婷 | 中文字幕不卡一区 | 日韩一区二区在线播放 | 99精品免费 | 久久精品91 | 国产在线网站 | 亚洲欧美在线一区 | 国产激情在线观看视频 | 国产高清免费视频 |