为作者的WooCommerce产品页面禁用“出价”按钮

问题描述:

我希望从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

由于这个按钮已经由您或一些插件定制的,我不知道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