Skip to content

Instantly share code, notes, and snippets.

View dhirenpatel22's full-sized avatar

Dhiren Patel dhirenpatel22

View GitHub Profile
@dhirenpatel22
dhirenpatel22 / woo-subscription-custom-failed-payment-retry-rules.php
Created April 28, 2026 02:40
Custom Failed Payment Retry Rules for WooCommerce Subscriptions
<?php
/**
* Custom Failed Payment Retry Rules for WooCommerce Subscriptions
* @param $default_retry_rules_array
* @return array
*/
function wc_subscription_custom_retry_rules($default_retry_rules_array ){
return array(
array(
@dhirenpatel22
dhirenpatel22 / woo-subscription-add-parent-id-to-renewal-orders.php
Created April 28, 2026 02:38
Add Parent ID to the Renewal orders of the Subscriptions
<?php
/**
* Add Parent ID to the Renewal orders of the Subscriptions
* Compatible with High-Performance Order Storage (HPOS)
*
* @param WC_Subscription $subscription
* @param WC_Order $order
*/
function add_parent_order_id_to_renewal_orders( $subscription, $order ) {
@dhirenpatel22
dhirenpatel22 / custom-meta-fields-woo-admin-order-search.php
Created April 28, 2026 02:18
Extend WooCommerce admin order search with custom meta fields.
<?php
/**
* Extend WooCommerce admin order search with custom meta fields.
*
* Usage:
* - Add your custom meta keys in the $custom_fields array.
* - Works for searching order meta in admin order list.
*/
add_filter( 'woocommerce_shop_order_search_fields', function( $search_fields ) {
@dhirenpatel22
dhirenpatel22 / related-products-query-to-yoast-primary-category.php
Created April 25, 2026 13:42
Change related products query to pull items from Yoast Primary Category
@dhirenpatel22
dhirenpatel22 / change-woo-coupon-labels.php
Created April 25, 2026 13:40
Change WooCommerce Coupon Labels
<?php
/**
* Change Coupon to Promo code
* @param $translated_text
* @param $text
* @param $text_domain
* @return mixed
*/
function woocommerce_rename_coupon_field_on_cart($translated_text, $text, $text_domain ){
@dhirenpatel22
dhirenpatel22 / hide-shipping-rates-when-free-shipping-is-available.php
Created April 25, 2026 13:32
Hide shipping rates when free shipping is available.
<?php
/**
* Hide shipping rates when free shipping is available.
* Updated to support WooCommerce 2.6 Shipping Zones.
*
* @param array $rates Array of rates found for the package.
* @return array
*/
function hide_shipping_when_free_is_available( $rates ) {
$free = array();
@dhirenpatel22
dhirenpatel22 / disable-yoast-next-prev-rel-links-author-page.php
Created April 25, 2026 07:28
Disable Yoast next and prev rel links on author pages
@dhirenpatel22
dhirenpatel22 / allow-svg-upload-media.php
Created April 25, 2026 07:25
Allow SVG upload in media
<?php
/**
* Allow SVG
*/
add_filter('wp_check_filetype_and_ext', function ($data, $file, $filename, $mimes) {
global $wp_version;
if ($wp_version !== '4.7.1') {
return $data;
}
@dhirenpatel22
dhirenpatel22 / authenticate-Rest-API-WordPress.php
Created April 25, 2026 06:51
Authenticate Rest API in WordPress
<?php
/**
* Authenticate Rest API in WordPress
**/
add_filter( 'rest_authentication_errors', function( $result ) {
// If a previous authentication check was applied,
// pass that result along without modification.
if ( true === $result || is_wp_error( $result ) ) {
@dhirenpatel22
dhirenpatel22 / disable-yoast-seo-auto-redirect.php
Created April 25, 2026 06:48
Disable Yoast SEO Auto Redirects
<?php
// Disable automatic redirect for posts
add_filter('Yoast\WP\SEO\post_redirect_slug_change', '__return_true' );
// Disable automatic redirect for taxonomies
add_filter('Yoast\WP\SEO\term_redirect_slug_change', '__return_true' );
// Disable automatic redirect notifications for Posts or Pages moved to Trash or changed url
add_filter('Yoast\WP\SEO\enable_notification_post_trash', '__return_false' );