我想删除/禁用/隐藏的“出价”按钮,从产品页面在WooCommerce的文章作者的文章。
我使用WC供应商pro + Woocommerce + Wp Geine Auctions + WC供应商拍卖。
请找到下面屏幕截图的链接:

我该怎么做呢?
发布于 2017-08-25 12:06:58
由于这个按钮已经由您或一些插件定制,我不确定它是否能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文件中,或者在任何插件文件中。
这段代码是经过测试和工作的。你会得到这个:

这是:

https://stackoverflow.com/questions/45435011
复制相似问题