2017-08-01 85 views
1

我希望從WooCommerce的產品頁面中刪除/禁用/隱藏「投標」按鈕,以便發佈帖子的作者。爲作者的WooCommerce產品頁面禁用「出價」按鈕

我使用WC供應商pro + Woocommerce + Wp Geine拍賣+ WC供應商拍賣。

請找到屏幕下面的鏈接拍:

enter image description here

的直播Link to the product

我怎麼能做到這一點嗎?

+0

@LoicTheAztec請指導。添加了 – Jay

+0

屏幕截圖。 http://i.imgur.com/RtMaWRX.png – Jay

+0

你有沒有試過這個...你在評論中問我這個問題,所以反饋意見會很好。謝謝 – LoicTheAztec

回答

1

由於這個按鈕已經由您或一些插件定製的,我不知道100%,它會爲你工作,即使它的工作原理我的測試服務器上。

第一個函數是一個條件函數,用於在當前用戶是本產品的作者(供應商)時檢測產品。

然後在商店和檔案頁面添加到購物車按鈕被替換爲喜歡的產品的自定義按鈕。

要完成單品頁面上的按鈕由帶有自定義文本(這裏是「不允許」)假的按鈕替換...

下面是代碼:

// Custom conditional function (detecting the vendor of a product) 
if(! function_exists('is_the_vendor')){ 
    function is_the_vendor($product){ 

     $current_user_id = get_current_user_id(); 

     $product_id = method_exists($product, 'get_id') ? $product->get_id() : $product->id; 

     // Get the product post object to get the post author 
     $post_obj = get_post($product_id); 
     $post_author = $post_obj->post_author; 

     if($post_author == $current_user_id) return true; 
     else return false; 
    } 
} 

// Shop and archives pages: we replace the button add to cart by a link to the product 
add_filter('woocommerce_loop_add_to_cart_link', 'custom_text_replace_button', 10, 2); 
function custom_text_replace_button($button, $product ) { 

    if(is_the_vendor($product)){ 
     $button_text = __("View product", "woocommerce"); 
     return '<a class="button" href="' . $product->get_permalink() . '">' . $button_text . '</a>'; 
    } else { 
     return $button; 
    } 
} 
// replacing add to cart button and quantities by a custom inactive button 
add_action('woocommerce_single_product_summary', 'replacing_template_single_add_to_cart', 1, 0); 
function replacing_template_single_add_to_cart() { 
    global $product; 

    if(is_the_vendor($product)): 

     // Removing add to cart button and quantities 
     remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30); 

     // The text replacement 
     add_action('woocommerce_single_product_summary', function(){ 

      // set below your custom text 
      $text = __('Not allowed', 'woocommerce'); 

      // Temporary style CSS 
      $style_css = 'style="border: solid 1px red; padding: 0 6px; text-align: center;"'; 

      // Output your custom text 
      echo '<a class="button custom-button" style="background-color: grey !important;">'.$text.'</a>'; 
     }, 30); 

    endif; 
} 

代碼進入你活動的兒童主題(或主題)的function.php文件,或者在任何插件文件中。

此代碼已經過測試並可正常工作。你會得到這樣的:

enter image description here

這:

enter image description here

相關問題