Created
July 4, 2023 17:40
-
-
Save yaovicoder/5392afb40e27736e79a75f45a988c1cd to your computer and use it in GitHub Desktop.
This wordpress plugin sets the WooCommerce Shop page title based on the connected user's role
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: WooCommerce Shop Page Title | |
Description: Sets the WooCommerce Shop page title based on the connected user's role. | |
Version: 1.0 | |
Version: 1.0 | |
Author: Yaovi Ametepe | |
Released: July 4th, 2023 | |
*/ | |
/** | |
* Sets the WooCommerce Shop page title based on the connected user's role. | |
* | |
* This plugin modifies the default Shop page title in WooCommerce based on the role of the connected user. | |
* If the connected user has the 'customer' role, the Shop page title is set to 'Customer Page'. For all other roles, | |
* the original WooCommerce Shop page title is maintained. | |
* | |
* @package WooCommerce Shop Page Title | |
*/ | |
/** | |
* . | |
* | |
* This function is hooked to the 'woocommerce_page_title' filter and modifies the default Shop page title in WooCommerce. | |
* If the connected user has the 'customer' role, the Shop page title is set to 'Customer Page'. For all other roles, | |
* the original WooCommerce Shop page title is maintained. | |
* | |
* @param string $title The original WooCommerce Shop page title. | |
* @return string The modified Shop page title, either 'Customer Page' if the user has the 'customer' role or the original | |
* Shop page title for other roles. | |
*/ | |
function set_woocommerce_shop_page_title($title) { | |
if (is_user_logged_in()) { | |
$user = wp_get_current_user(); | |
if (in_array('client_pro', $user->roles)) { | |
$title = 'Customer Page'; | |
} | |
} | |
return $title; | |
} | |
add_filter('woocommerce_page_title', 'set_woocommerce_shop_page_title', 10, 1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment