如何给WooCommerce产品追加‘course’,同时排除含‘bundle’的记录?
How to Append 'course' to WooCommerce Products (Excluding Those with 'bundle')
Absolutely feasible—this is a common use case that can be handled with a targeted UPDATE query tailored to WooCommerce's database structure. WooCommerce stores product titles in the wp_posts table (your table prefix might differ, e.g., wp_ is the default) where post_type = 'product'. Here's the step-by-step solution:
The Core SQL Query
UPDATE wp_posts SET post_title = CONCAT(post_title, ' course') WHERE post_type = 'product' AND post_title NOT LIKE '%bundle%';
Breakdown of the Query:
UPDATE wp_posts: Targets the posts table where WooCommerce products are stored.SET post_title = CONCAT(post_title, ' course'): Appends the string ' course' (note the leading space to avoid merging words awkwardly) to the existing product title.WHERE post_type = 'product': Ensures we only modify actual products, not pages, posts, or other post types.AND post_title NOT LIKE '%bundle%': Excludes any product whose title contains the word 'bundle' (the%wildcards match any characters before or after 'bundle').
Critical Pre & Post Steps:
- Backup First: Always back up your database before running
UPDATEqueries—once executed, changes can't be undone easily. - Check Table Prefix: If your WordPress installation uses a custom table prefix (not
wp_), replacewp_postswith your actual prefix (e.g.,my_store_posts). - Case Sensitivity: By default,
LIKEin MySQL is case-insensitive on most collations. If you need strict case matching (e.g., exclude only 'Bundle' not 'bundle'), useNOT LIKE BINARY '%bundle%'.
Example Behavior:
- A product titled "Beginner Python" will become "Beginner Python course".
- A product titled "Web Dev Bundle" will remain completely unchanged.
内容的提问来源于stack exchange,提问作者Eoin
相关产品推荐
相关产品推荐

