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

Sunday, May 15, 2022

[FIXED] How do I replace the dash by round brackets on WooCommerce product variations?

 May 15, 2022     php, product-variations, variations, woocommerce, wordpress     No comments   

Issue

I would like to replace the dash ( - ) with round brackets ( ) around WooCommerce product variation names.

Normally a WooCommerce product variation is displayed like this:

Product name - variation name

Sometimes this dash can be confused by a minus, and it looks like it's the main product minus the variation. This depends on both the product and variation names.

So the displayed product variation must be, for example:

Product name (variation name)

Solution

add_filter('woocommerce_product_variation_get_name', 'woocommerce_product_get_name', 10, 2);

function woocommerce_product_get_name($name, $product) {

    if (strpos($name, '-') !== false) {
        $modified_name_last = substr($name, strrpos($name, '-') + 1);
        $modified_name_first = substr($name, 0, strrpos($name, "-"));
        $name = $modified_name_first . ' (' . $modified_name_last . ')';
    }

    return $name;
}


Answered By - mujuonly
Answer Checked By - Cary Denson (PHPFixing Admin)
  • 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