Skip to content

Instantly share code, notes, and snippets.

View TanvirHasan19's full-sized avatar
🏘️
Working from home

Tanvir Hasan TanvirHasan19

🏘️
Working from home
View GitHub Profile
@TanvirHasan19
TanvirHasan19 / functions.php
Created April 13, 2026 06:09
WWOF + WWPP — hide non-wholesale variations in REST when loading
/**
* Temporary: WWOF + WWPP — hide non-wholesale variations in REST when loading
* /wc/v3/products/{id}/variations?wwof=… (parent + dropdown on order form).
* Remove after Wholesale Order Form includes an official fix.
*/
add_filter(
'woocommerce_rest_product_variation_object_query',
static function ( $args, $request ) {
if ( ! $request instanceof WP_REST_Request || ! $request->get_param( 'wwof' ) ) {
return $args;
@TanvirHasan19
TanvirHasan19 / functions.php
Created April 10, 2026 00:35
clear all WWPP product-category percentage discounts
<?php
/**
* One-off: clear all WWPP product-category percentage discounts (options taxonomy_{id})
* and sync product meta for category-sourced wholesale flags.
*
* Requires: WooCommerce + Wholesale Prices Premium active.
* Run on staging first; keep a backup.
*/
if ( ! defined( 'ABSPATH' ) ) {
require __DIR__ . '/wp-load.php';
@TanvirHasan19
TanvirHasan19 / deactivate.SQL
Created April 1, 2026 02:24
SQL (deactivate vendors with 0 products)
Replace wp_ with your actual table prefix.
-- 1) Preview vendors that will be affected
SELECT u.ID, u.user_login
FROM wp_users u
JOIN wp_usermeta cap
ON cap.user_id = u.ID
AND cap.meta_key = 'wp_capabilities'
AND cap.meta_value LIKE '%"vendor"%'
@TanvirHasan19
TanvirHasan19 / .htaccess
Created March 31, 2026 05:32
BEGIN LiteSpeed for Lucel
# BEGIN Really Simple Security Redirect
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP:X-Forwarded-Proto} !https [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>
# END Really Simple Security Redirect
# BEGIN LSCACHE
@TanvirHasan19
TanvirHasan19 / functions.php
Last active March 31, 2026 05:22
Force re-sync Wholesale Payments invoice meta from Stripe.
// Optional manual map from LOCAL -> LIVE (order_id => stripe_invoice_id).
if ( ! defined( 'WPAY_RESYNC_ORDER_MAP' ) ) {
define( 'WPAY_RESYNC_ORDER_MAP', array() );
}
// Optional force only specific order IDs.
if ( ! defined( 'WPAY_RESYNC_ORDER_IDS' ) ) {
define( 'WPAY_RESYNC_ORDER_IDS', array() );
}
@TanvirHasan19
TanvirHasan19 / functions.php
Created March 3, 2026 03:34
Translate "pending" status in Wholesale Payments
/**
* Start output buffer before Wholesale Payments section is rendered.
*/
add_action( 'woocommerce_order_details_after_order_table', function( $order ) {
// Only on front-end order view (e.g. My Account → View order).
if ( ! is_account_page() && ! is_order_received_page() ) {
return;
}
if ( $order->get_payment_method() !== 'wc_wholesale_payments' ) {
return;
@TanvirHasan19
TanvirHasan19 / functions.php
Last active February 6, 2026 09:11
Force dashboard menu order
/**
* WC Vendors: Force dashboard menu order (includes "My Custom Page").
* Add to child theme functions.php or a snippets plugin.
*/
add_action( 'wp_footer', function () { ?>
<style>
@media screen and (min-width: 1071px) {
ul.wcv-dashboard-menu.horizontal.black.primary {
margin-left: 20px;
}
@TanvirHasan19
TanvirHasan19 / functions.php
Created January 26, 2026 02:47
Bulk reset store credits to zero for all users in a given role(s).
/**
* Bulk reset store credits to zero for all users in a given role(s).
*
* SETUP:
* 1. Set the role(s) in ACFW_BULK_RESET_DEFAULT_ROLE below (one role, or comma-separated: 'wholesale_customer,trade').
* 2. Add this snippet (e.g. Code Snippets or a custom plugin). Advanced Coupons (Store Credits) must be active.
*
* TO RUN:
* - Option A: Go to the Dashboard — a "Run now" link is shown. Click it (must have manage_woocommerce).
* - Option B: Open the URL manually with ?role=ROLE and a valid _wpnonce (e.g. from the Dashboard link). The role in the URL overrides the default.
@TanvirHasan19
TanvirHasan19 / functions.php
Last active January 21, 2026 08:18
Add this as a small MU-plugin or in your theme/plugin (so updates won’t overwrite it):
/**
* WC Vendors Pro: clean up shipping label and avoid "Vendor Shipping".
*/
add_filter( 'wcvendors_pro_shipping_label', function( $label, $vendor_id, $rate ) {
// Change this if you want a different default.
$fallback_method = 'Standard Shipping';
$vendor_term = function_exists( 'wcv_get_vendor_name' ) ? wcv_get_vendor_name( true, true ) : 'Vendor';
@TanvirHasan19
TanvirHasan19 / functions.php
Created January 15, 2026 04:52
Fix HTML entities in XML feeds
/**
* Fix HTML entities in XML feeds
*/
add_filter( 'adt_product_feed_xml_attribute_handling', function( $handled, $product, $key, $value, $feed_config, $channel_attributes, $feed ) {
if ( $handled || ! is_object( $product ) || ! is_object( $feed ) ) {
return $handled;
}
$target_feed_id = 37281;
$is_target_feed = false;