Php Woocommerce-当用户是产品作者时,删除“添加到购物车”按钮
当当前用户是登录用户时,我试图删除“添加到购物车”按钮,并添加“编辑产品”链接。但这完全破坏了我的设计,而且不起作用:Php Woocommerce-当用户是产品作者时,删除“添加到购物车”按钮,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,当当前用户是登录用户时,我试图删除“添加到购物车”按钮,并添加“编辑产品”链接。但这完全破坏了我的设计,而且不起作用: 仅显示12种产品中的2种 它在第一个产品中不断显示“添加到购物车”按钮 <?php global $current_user; get_currentuserinfo(); if (is_user_logged_in() && $current_user->ID == $post->post_author) { remove_action
- 仅显示12种产品中的2种
- 它在第一个产品中不断显示“添加到购物车”按钮
<?php global $current_user; get_currentuserinfo(); if (is_user_logged_in() && $current_user->ID == $post->post_author) { remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close', 10 ); remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 ); add_action( 'woocommerce_after_shop_loop_item', 'btn_edit_own_product', 10 ); function btn_edit_own_product() { edit_post_link('Edit Product'); } } ?>
/* remove add-to-cart from shop page for product author */
add_action('woocommerce_after_shop_loop_item_title','user_filter_addtocart_for_shop_page') ;
function user_filter_addtocart_for_shop_page(){
$user_id = get_current_user_id();
$author_id = get_post_field('post_author', get_the_ID());
if($user_id == $author_id){
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
}
}
/* remove add-to-cart from single product page for product author */
add_action('woocommerce_before_single_product_summary','user_filter_addtocart_for_single_product_page') ;
function user_filter_addtocart_for_single_product_page(){
$user_id = get_current_user_id();
$author_id = get_post_field('post_author', get_the_ID());
if($user_id == $author_id){
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
}
}
希望这对你有帮助
欲了解更多详情,请访问:
请尝试使用此代码。将其放在当前主题的functions.php中
add_action( 'woocommerce_shop_loop', 'custom_woocommerce_shop_loop' );
function custom_woocommerce_shop_loop() {
global $post;
$current_user = wp_get_current_user();
if (is_user_logged_in() && $current_user->ID == $post->post_author) {
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );;
add_action( 'woocommerce_after_shop_loop_item', 'btn_edit_own_product', 10 );
}
}
function btn_edit_own_product() {
edit_post_link('Edit Product');
}
你把这个代码放在什么地方?这是代码本身还是它的一部分?