0

I am currently working on a project that is based on WordPress and as an e-commerce platform, it uses WooCommerce. I made a product migration from an old site that has the product titles written in uppercase.

Currently I have this html code for the titles inside a product:

<h1 class="product_title netry-title">PRODUCT TITLE</h1>

So I want the product title to appear like "Product Title". Is there any way to make this happen?

I saw some answers that use JS or JQuery, but did not work for me.

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
Efstef
  • 88
  • 9
  • This should help: https://stackoverflow.com/questions/20853335/uppercase-issue-for-title-in-wordpress – my_workbench Aug 15 '20 at 14:45
  • Is it possible to use something like `echo ucwords(strtolower('PRODUCT TITLE'));` via PHP? Output: `Product Title`. – Ihor Vyspiansky Aug 15 '20 at 14:51
  • 2
    Sounds like fixing it once in database would make most sense – charlietfl Aug 15 '20 at 15:05
  • With PHP using [`ucfirst()`](https://stackoverflow.com/questions/20853335/uppercase-issue-for-title-in-wordpress), or maybe using CSS `text-transform` property: [Make the first character Uppercase in CSS](https://stackoverflow.com/questions/5577364/make-the-first-character-uppercase-in-css/5577380#5577380)… **The best solution is to fix that in database** as @charlietfl mention. – LoicTheAztec Aug 15 '20 at 15:42
  • @maniksidana I tried this but this will make only the first letter uppercase. I want something like e.g "Product Title Test". The first letter of every word to be Capital letter. – Efstef Aug 17 '20 at 06:04
  • @charlietfl. is it possible to be done with any query directly in DB? This must be automated as we speak for at least 1000 products. – Efstef Aug 17 '20 at 06:06
  • @IhorVyspiansky I will try and add it in the woocommerce template and see if it works that way. – Efstef Aug 17 '20 at 06:07
  • 1
    Yes...there are even worpress plugins you can use to modify entries in db, or write your own queries in php to clean it up – charlietfl Aug 17 '20 at 06:08
  • @charlietfl I will go make a search about this and get back with a answer. – Efstef Aug 17 '20 at 07:37
  • 1
    Mostly covered by "[Turn all titles in wordpress powered site into "Capitalized" case](https://stackoverflow.com/q/3033988/90527)" – outis Jan 19 '22 at 05:38
  • What have you tried so far? Where are you stuck? Why is this tagged with PHP, CSS, SQL, while you haven't shared any related code? – Nico Haase Jan 24 '22 at 10:58

1 Answers1

0

After some digging into this and with the help from @outis that pointed me to another post i had the outcome that i wanted. What i was asking was mostly covered here "Turn all titles in wordpress powered site into "Capitalized" case"

Below is the answer from that post (as presented from the user brendan):

DROP FUNCTION IF EXISTS proper;
SET GLOBAL  log_bin_trust_function_creators=TRUE;
DELIMITER |
CREATE FUNCTION proper( str VARCHAR(128) )
RETURNS VARCHAR(128)
BEGIN
  DECLARE c CHAR(1);
  DECLARE s VARCHAR(128);
  DECLARE i INT DEFAULT 1;
  DECLARE BOOL INT DEFAULT 1;
  DECLARE punct CHAR(17) DEFAULT ' ()[]{},.-_!@;:?/';
  SET s = LCASE( str );
  WHILE i < LENGTH( str ) DO 
    BEGIN
      SET c = SUBSTRING( s, i, 1 );
      IF LOCATE( c, punct ) > 0 THEN
        SET BOOL = 1;
      ELSEIF BOOL=1 THEN 
        BEGIN
          IF c >= 'a' AND c <= 'z' THEN 
            BEGIN
              SET s = CONCAT(LEFT(s,i-1),UCASE(c),SUBSTRING(s,i+1));
              SET BOOL = 0;
            END;
          ELSEIF c >= '0' AND c <= '9' THEN
            SET BOOL = 0;
          END IF;
        END;
      END IF;
      SET i = i+1;
    END;
  END WHILE;
  RETURN s;
END;
|
DELIMITER ;

I twicked this a bit and removed the SET GLOBAL log_bin_trust_function_creators=TRUE; because of the limitation i had on the server. (Shared Hosting Server).

After that i had to target the titles of the products only. So i changed the default SQL from the post to this

UPDATE wp_posts SET post_title = proper(post_title) WHERE `post_type` LIKE 'product';

Also did the same product_variation as there where some Variation products in the shop.

I then had to regenerate the database lookup form inside woocommerce

(Admin dashboard ->Woocommerce -> Status -> Tools -> Product lookup tables : Regenarate) and a Term counts (Inside Tools as well).

In some cases it might be needed to Update database (this is also inside Tools tab), but before you do anything of the above, make sure to have a backup of your database.

As a general info, product meta values are also stored in wp_postmeta table with post_id as relational index (the product ID). But if nothing of the above works, then try to update also the wp_postmeta using an SQL Query.

As i mentioned before, always backup your Database and then start working with tests.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Efstef
  • 88
  • 9