Skip to content

Instantly share code, notes, and snippets.

View dhirenpatel22's full-sized avatar

Dhiren Patel dhirenpatel22

View GitHub Profile
@dhirenpatel22
dhirenpatel22 / exclude-taxonomy-sitemap-xml.php
Created March 16, 2026 19:06
Remove child category from Yoast SEO Sitemap.xml
<?php
// Remove child category from Sitemap.xml
add_filter( 'wpseo_sitemap_url', 'sitemap_exclude_taxonomy' );
function sitemap_exclude_taxonomy( $url = null, $type = null, $term = null ) {
$dataurl = $url;
$url = explode('brands/',$url);
$url_data = explode('/',$url[1]);
$term_slug = $url_data[0];
$texonomy = get_term_by('slug', $term_slug , "wsac_cse_make");
if(!$texonomy->parent)
@dhirenpatel22
dhirenpatel22 / wp-smart-debug.php
Created March 16, 2026 18:13
WordPress Smart Debug
<?php
/**
* WordPress Debug Configuration
*
* This file handles WordPress debug settings based on the 'debug' GET parameter.
* It sets up WP_DEBUG constants and error display settings.
*
* @package WordPress
* @subpackage Configuration
*/
@dhirenpatel22
dhirenpatel22 / rename-admin-sidebar-links.php
Last active March 11, 2026 18:20
Rename Admin Sidebar Links
@dhirenpatel22
dhirenpatel22 / reorder-rearrange-admin-sidebar-links.php
Created March 11, 2026 18:14
Reorder / Rearrange Admin Sidebar Links
@dhirenpatel22
dhirenpatel22 / remove-hide-admin-sidebar-links.php
Last active March 11, 2026 18:10
Remove / Hide Admin Sidebar Links
@dhirenpatel22
dhirenpatel22 / wc-hide-all-shipping-if-free-shipping-is-available.php
Created November 25, 2020 12:03
Hide shipping rates when free shipping is available
<?php
/**
* Hide shipping rates when free shipping is available.
*
* @param array $rates Array of rates found for the package.
* @return array
*/
function hide_shipping_when_free_is_available( $rates ) {
$free = array();
foreach ( $rates as $rate_id => $rate ) {
@dhirenpatel22
dhirenpatel22 / exclude-category-from-shop.php
Created July 31, 2020 13:55
Exclude specific categories from the Shop page
<?php
/**
* Exclude specific categories from the Shop page
* @param $terms
* @param $taxonomies
* @param $args
* @return array
*/
function ts_get_subcategory_terms($terms, $taxonomies, $args ) {
$new_terms = array();
@dhirenpatel22
dhirenpatel22 / change-free-shipping-label.php
Created July 19, 2020 13:22
Change label for free standard shipping, when the shipping method’s rate returns $0.00
<?php
/**
* Change label for free standard shipping, when the shipping method’s rate returns $0.00
* @param $full_label
* @param $method
* @return string
*/
function custom_display_zero_shipping_cost($full_label, $method){
if( $method->cost == 0.0 ) {
$full_label = '<span class=”woocommerce-Price-amount amount”>Free Shipping</span>';
@dhirenpatel22
dhirenpatel22 / redirect-after-reset-password-based-on-userrole.php
Created July 19, 2020 13:16
Redirect user to different page based on user role after password reset from the backend screen
<?php
/**
* Redirect user to different page based on userrole after password reset from backend screen
* @param $user
*/
function custom_redirect_retail_page_based_on_role($user) {
$user_roles = (array) $user->roles;
if ( in_array('userrole1', $user_roles) ) {
wp_redirect( 'Custom Page Link' );
@dhirenpatel22
dhirenpatel22 / new-subscription-webhook-topic.php
Created July 19, 2020 13:06
Add New Webhook topics for WooCommerce Subscription
<?php
function add_custom_filters_and_actions() {
add_filter( 'woocommerce_webhook_topic_hooks', 'add_custom_wcs_topics', 30, 2 );
add_filter( 'woocommerce_valid_webhook_events', 'add_custom_wcs_events', 20, 1 );
add_filter( 'woocommerce_webhook_topics' , 'add_custom_wcs_topics_admin_menu', 20, 1 );