基於角色的可變產品
P粉174151913
P粉174151913 2023-08-06 13:06:26
0
1
453
<p>我有一個銷售可變產品的WooCommerce商店。 <br /><br />例如:吹箭可變選項:單一物品盒裝4個。 <br /><br />我正在嘗試使可變產品在登入時不顯示單一物品選項。我已經做到了隱藏選項標籤文字的程度,但並沒有完全刪除選項。 <br /><br />可變選項</p><p><br /></p> <pre class="brush:php;toolbar:false;">add_filter('woocommerce_variation_option_name', 'custom_hide_single_item_option', 10, 1); function custom_hide_single_item_option($term_name) { // Get the current user's roles $user = wp_get_current_user(); $user_roles = (array)$user->roles; // Define the roles to exclude $roles_to_exclude = array('reseller', 'reseller 1', 'administrator'); // If the user has any of the excluded roles, remove the "Single Item (1pc)" option if (array_intersect($user_roles, $roles_to_exclude) && $term_name === 'Single Item (1pc)') { return false; } return $term_name; }</pre> <p>我提供了我正在使用的PHP程式碼片段,並附上了該程式碼片段的結果截圖。 </p>
P粉174151913
P粉174151913

全部回覆(1)
P粉904450959

我對描述和/或圖片中的問題並不太理解/看得明白。我只看到一個下拉式選單,可以選擇購買4個。您想要移除下拉式選單嗎?在這種情況下,我認為問題不在於PHP嗎?

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!