
內容簡介
Visibility Control for WooCommerce 可以幫助您隱藏 WordPress 頁面上的特定標記、選單和內容。
您可以根據以下條件顯示/隱藏 HTML 元素、選單和其他細節:
1.使用者購買特定 WooCommerce 產品或變化,或
2.使用者已登入或登出。
您只需要將 CSS 類別添加到您的元素 div 或 span 中即可,如下所述:
範例:
如果產品或變化的 ID 為 123
要顯示元素/選單項目給購買以上產品的使用者,添加此 CSS 類別:visible_to_product_123
要隱藏元素/選單項目不顯示給購買以上產品的使用者,添加此 CSS 類別:hidden_to_product_123
要顯示元素/選單項目給登入的使用者,添加此 CSS 類別:visible_to_logged_in 或 hidden_to_logged_out
要隱藏元素/選單項目不顯示給登入的使用者,添加此 CSS 類別:visible_to_logged_out 或 hidden_to_logged_in
針對使用者角色:
* 要顯示元素/選單項目給管理者角色的使用者,添加此 CSS 類別:visible_to_role_administrator 或 hidden_to_role_administrator
* 注意:如果要將元素顯示給多個特定角色,您需要為每個角色都加入一個元素。要隱藏特定的多個角色的元素/選單,您可以將元素添加一次,然後將多個類別添加到同一個元素。
功能機制
多個 CSS 類別:如果添加了多個可見性控制類別,則所有這些類別都必須符合條件才能使元素保持可見。如果其中任何一個隱藏了元素,則它將被隱藏。例如:visible_to_product_123 visible_to_product_124 只會將元素顯示給同時購買了兩個產品的使用者。
隱藏的數據/元素會到達瀏覽器,但使用者看不到它們。
為所有需要根據上述規則隱藏的 CSS 元素添加到頁面中的 CSS。
頁面加載後,使用 jQuery (如果可用) 從頁面中刪除這些元素,因此即使在檢查中也無法使用。
在頁面加載後呈現的元素會被隱藏,但不從 DOM/頁面中刪除。
未來的發展
根據這個功能的興趣,我們將決定是否添加設置、短代碼和/或 Gutenberg 區塊選項來實現此功能。
外掛標籤
開發者團隊
② 後台搜尋「Visibility Control for WooCommerce」→ 直接安裝(推薦)
原文外掛簡介
Visibility Control for WooCommerce helps you hide or show messages, menu and content for specific criterion anywhere on your WordPress page.
You can show/hide HTML elements, menus, and other details based on:
1. User’s purchase of a particular WooCommerce Product or Variation, Or
2. User is Logged In or Logged Out.
You simply need to add a CSS class to your element div or span. As explained here:
Example:
If Product or Variation ID is 123
To show the element/menu item to user who purchased above product, add this CSS class: visible_to_product_123
To hide the element/menu item from user who purchased above product, add this CSS class: hidden_to_product_123
To show the element/menu item to a logged-in user, add this CSS class: visible_to_logged_in OR hidden_to_logged_out
To hide the element/menu item from a logged-in user, add this CSS class: visible_to_logged_out OR hidden_to_logged_in
For user’s role:
* To show the element/menu item to a user will role administrator, add this CSS class: visible_to_role_administrator OR hidden_to_role_administrator
* Note: To show an element to multiple specific roles only, you need add the element multiple times, one for each role. To hide an element/menu from specific multiple roles only you can add the element once add multiple classes to the same element.
Mechanism of Functioning
Multiple CSS Classes: If multiple visibility control classes are added, ALL of them must meet the criterion to keep the element visible. If any one of them hides the element, it will be hidden. For example: visible_to_product_123 visible_to_product_124 will show the element only to those who have purchased to both products.
Hidden data/elements reaches the browser. Though user’s do not see it.
CSS is added to the page for all CSS elements that needs to be hidden based on above rules.
After page is loaded. These elements are removed from page using jQuery (if available), so it won’t be available even on Inspect.
Elements rendered after the page load are hidden but not removed from DOM/page.
Future Development
Depending on the interest in this feature, we will decide on adding a setting, shortcode and/or a Gutenberg Block option to achieve this feature.
Other Visibility Control Plugins:
Visibility Control for LearnDash LMS
Visibility Control for WP Courseware LMS
Visibility Control for LearnPress LMS
Visibility Control for LifterLMS
Visibility Control for MasterStudyLMS
Visibility Control for Sensei LMS
