You can use the conditional checks to simply build a new return value for the filter. So run the filter once and put all your code in there.
Your second example doesn’t really make sense because no matter what, you’re returning $name, can you explain that more?
add_filter( 'woocommerce_cart_item_name', 'cart_variation_description', 20, 3);
function wpse306625_cart_variation_description( $name, $cart_item, $cart_item_key ) {
$output="";
if ( is_checkout() ) {
$item_data = $cart_item_key['data'];
$post = get_post($item_data->id);
$thumb = get_the_post_thumbnail($item_data->id, array( 32, 50));
$output="<div id="jwf_checkout_thumbnail" style="float: left; padding-right: 8px">" . $thumb . '</div>' ;
}
else {
$output .= $name;
}
return $output;
}
Related Posts:
- Hide some items from Screen options in dashboard for products
- Exclude Empty Child Categories in Menu
- Add to cart php not working [closed]
- woocommerce change currency per category [closed]
- (Woocommerce) Order by price when entering specific category
- Which method is more correct for removing WooCommerce Extensions menu item?
- remove empty paragraphs from the_content?
- How to display custom field in woocommerce orders in admin panel?
- Issues with title-tag and document_title_parts
- How to create a custom order status in woocommerce!
- Remove Actions/Filters added via Anonymous Functions
- Set JPEG compression for specific custom image sizes
- Define custom Page Template without its own .php file
- Add class to menu items of one specific menu (nav_menu_css_class)
- How to show product SKU on product page
- How to influence the information displayed on widget inside wp-admin
- How to get woocommerce inventory status [closed]
- Woocommerce add to simple product attribute programmatically [closed]
- Removing default image size list in Media Box
- How to restrict actions and filters “properly” by conditions
- Filter the query ONLY for the search results page
- opening links in new tab using – add_filter( ‘the_content’, ‘make_clickable’);
- Using add_filter() in Widgets
- Customize WordPress Media Manager – Media Window
- Apply jquery script to only woocommerce product pages and categories
- How to reduce original image quality on upload?
- Is it possible to use a forgot password url filter?
- In WooCommerce I need to modify the thankyou.php page [closed]
- How can I add an extra WooCommerce hook
- syntax for remove_filter in parent theme with class
- Add body class of category parent
- Wrap gutenberg block ‘div’ in other elements/extra HTML
- Convert hyphen to underscore in permalinks
- Override parent theme function that is not hooked or in the functions.php file
- Remove Page Title from Static Frontpage
- Programmatically Add Font-Awesome Icons to Category Widget
- Remove bulk actions based on user role or capabilities
- How to Acheive the custom woocommerce category template
- Default or Preset Content for Custom Post Types
- Override a class function to include a custom template
- How to override filter in child theme?
- Removing title from page
- Remove product description from product archive page
- How to change a certain text or term of WordPress into a custom into the whole site?
- display 100 products per page on product category page [closed]
- Adding body class when post contains a specific shortcode
- Adding WooCommerce to a Custom Theme – not working [closed]
- Issue adding text after short description on product pages Woocommerce [closed]
- Replace Archive Widget Link Text
- Can you use admin pages functionality on the frontend of your site
- How to make unique add_filter to the_content of specific page template files – so each template gets its own addition
- Best way to programatically add “rel” attributes to page and post images
- change billing and shipping address 1 and 2 field placeholders [closed]
- add_filter priority problem
- Creating loop within functions.php
- Limit filter upgrader_post_install to a single plugin
- How to update feed only 2-3 times a week (for Feedburner email)?
- Manipulate Output of wp_list_something: select menu instead of li’s
- Clean-up script tags
- Override woocommerce wc-class function
- Display WooCommerce subscriptions for user [closed]
- Increment price for Woocommerce Minicart [closed]
- Change woocommerce products weight varation based its product category or tags? [closed]
- woocommerce target button with class after ajax update
- How to use IF Statement in WordPress?
- Gravity Forms field entries into wp_query loop [closed]
- Post thumbnail relative link and HTML modify
- Post Pagination Showing Same Posts Every Page
- Show excerpt for only first post in query
- Remove function or filter
- modify a function filter
- Super simple shortcode not working
- How would go about if I just want a temporary function?
- Generating rel=prev and rel=next only on wordpress categories
- How to make applyFilters function return false via functions.php
- WordPress function for 1 to for many
- Pass parameters to function through an action
- How to filter out shortcode when displaying the_excerpt() in the loop?
- Woocommerce checkout field maxlength, make input number field only (postcode)
- Accepted arguments value in hook functions
- Get current page_id before loop, in functions.php
- change in form-checkout.php by using code in functions.php
- Which action hook to use for function?
- Set quantity of woocommerce product on page visit [closed]
- Adding multiple taxonomy filters to functions.php
- str_replace function in theme
- Can’t check if a post has thumbnail adding filter to get_post_metadata()
- Product Tags in Add New product as checkbox list [closed]
- Calling a function from anywhere, used in different places
- Adding HTML to the end of every post with the Block Editor
- Last updated date function
- Selective Product Category for Carousel
- Modify a function without editing template
- I want to get product attirbute in the section below
- How to set default archive image without overriding first attached image? [closed]
- How do I add Bootstrap and LESS to my migrated WordPress site?
- How to add nav menu items to a specific position within a menu
- Passing values from a widget to a function within a plugin
- Only let plugin add actions to wp_head & wp_footer on single posts
- Publish/Update post is changing image links from file url to post url