Skip to content
Advertisement

Is it possible to change a WordPress/woocommerce title that is written with uppercase to appear capitalized?

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.

Advertisement

Answer

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.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement