PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, February 5, 2022

[FIXED] Is it possible to change a Wordpress/woocommerce title that is written with uppercase to appear capitalized?

 February 05, 2022     css, php, sql, woocommerce, wordpress     No comments   

Issue

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.


Solution

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.



Answered By - Efstef
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing