I am using a plugin on my website that made the following filter available:
Added filter ‘tinvwl_allow_addtowishlist_single_product’ that helps to show/hide the “Add to Wishlist” button for specific products on a single products page
The filter comes into place here:
if ( empty( $this->product ) || ! apply_filters( 'tinvwl_allow_addtowishlist_single_product', true, $this->product ) ) {
return;
}
I would now like to add this filter to a single product page to disable the "add to wishlist" functionality in some cases, but
- Where should I hook this filer? Should this be hooked at
woocommerce_before_single_product
as found on / ? - Which arguments do I need in order to pass the false option?
- How to add the filter statement correctly in my
functions.php
file?
My current attempt:
function disable_add {
$allow = false;
$product = $product->get_id();
return $allow;
return $product;
}
add_filter( 'tinvwl_allow_addtowishlist_single_product_summary','disable_add', 15, 2 );
I am using a plugin on my website that made the following filter available:
Added filter ‘tinvwl_allow_addtowishlist_single_product’ that helps to show/hide the “Add to Wishlist” button for specific products on a single products page
The filter comes into place here:
if ( empty( $this->product ) || ! apply_filters( 'tinvwl_allow_addtowishlist_single_product', true, $this->product ) ) {
return;
}
I would now like to add this filter to a single product page to disable the "add to wishlist" functionality in some cases, but
- Where should I hook this filer? Should this be hooked at
woocommerce_before_single_product
as found on https://businessbloomer/woocommerce-visual-hook-guide-single-product-page/ ? - Which arguments do I need in order to pass the false option?
- How to add the filter statement correctly in my
functions.php
file?
My current attempt:
function disable_add {
$allow = false;
$product = $product->get_id();
return $allow;
return $product;
}
add_filter( 'tinvwl_allow_addtowishlist_single_product_summary','disable_add', 15, 2 );
Share
Improve this question
edited Apr 11, 2019 at 10:58
BarrieO
asked Apr 11, 2019 at 9:12
BarrieOBarrieO
992 silver badges12 bronze badges
1 Answer
Reset to default 1I was almost correct in my attempt.
- I forgot to add the arguments in my function definition, which is important of course.
- I took the wrong function name, the
_summary
at the end was not needed.
The correct code is the following:
/* DISABLE ADD TO WISHLIST FOR USERS WHO AREN'T ADMIN OR SHOP MANAGER */
/* --- */
function remove_add_button ( $allow, $product ) {
$allow = false;
$product = $product->get_id();
return $allow;
return $product;
}
$user = wp_get_current_user();
if ( ! in_array( 'administrator', (array) $user->roles ) && ! in_array( 'shop_manager', (array) $user->roles ) ) {
add_filter( 'tinvwl_allow_addtowishlist_single_product','remove_add_button', 15, 2 );
}
As you can see I have also added a condition on the user role, so only admins & shop managers can use the button.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745601208a4635412.html
评论列表(0条)