Skip to content

Instantly share code, notes, and snippets.

View shameemreza's full-sized avatar
🇧🇩
Problem-Solver | WooCommerce Expert | Customer-First Mindset

Shameem Reza shameemreza

🇧🇩
Problem-Solver | WooCommerce Expert | Customer-First Mindset
View GitHub Profile
@shameemreza
shameemreza / woocommerce_saudi_kuwait_states.php
Created February 5, 2025 09:50 — forked from DevWael/woocommerce_saudi_kuwait_states.php
add saudi arabia and kuwait states to woocommerce
<?php
add_filter( 'woocommerce_states', 'dw_woocommerce_states' );
function dw_woocommerce_states( $states ) {
$states['KW'] = array(
'KWQ' => __('Dasmān','porto'),
'KWA' => __('Sharq','porto'),
'KWZ' => __('Mirgāb','porto'),
'KWW' => __('Jibla','porto'),
@shameemreza
shameemreza / gifted-subscriptions-change-to-manual.php
Last active January 15, 2025 01:56
Automatically handle gifted subscriptions: Set to Manual Renewal
// Hook into the subscription creation process
add_action( 'woocommerce_checkout_subscription_created', 'set_gifted_subscription_to_manual_renewal', 10, 2 );
function set_gifted_subscription_to_manual_renewal( $subscription, $order ) {
// Check if the subscription is gifted using the gifting plugin's functionality
if ( class_exists( 'WCS_Gifting' ) && WCS_Gifting::is_gifted_subscription( $subscription ) ) {
// Set the subscription to manual renewal
$subscription->set_requires_manual_renewal( true );
// Cancel any scheduled renewal actions
@shameemreza
shameemreza / modify-tax-behavior-for-deposits.php
Created January 8, 2025 03:32
Modify the tax behavior for deposits
add_filter('woocommerce_calculated_total', 'exclude_tax_from_deposits', 10, 2);
function exclude_tax_from_deposits($total, $cart) {
if (class_exists('WC_Deposits_Cart_Manager') && WC_Deposits_Cart_Manager::is_deposit_enabled_for_cart()) {
$total -= WC()->cart->get_taxes_total(); // Exclude taxes from deposit
}
return $total;
}
@shameemreza
shameemreza / woocommerce-subscriptions-custom-price-string.php
Created January 7, 2025 10:21
Change the price string globally for WooCommerce Subscriptions
add_filter( 'woocommerce_subscription_price_string', 'change_subscription_text', 10, 2 );
function change_subscription_text( $subscription_string, $subscription_details ) {
if ( $subscription_details['subscription_period'] === 'month' ) {
$subscription_string = str_replace( 'Monthly Subscription', '30 Day Subscription', $subscription_string );
}
return $subscription_string;
}
add_action('woocommerce_scheduled_subscription_payment', 'recalculate_taxes_before_payment', 10, 1);
function recalculate_taxes_before_payment($subscription_id) {
$subscription = wcs_get_subscription($subscription_id);
if ($subscription) {
foreach ($subscription->get_related_orders() as $renewal_order_id) {
$renewal_order = wc_get_order($renewal_order_id);
if ($renewal_order && 'pending' === $renewal_order->get_status()) {
@shameemreza
shameemreza / automatically-reset-inventory-when-subscription-cancele.php
Created December 20, 2024 05:27
Automatically Restock on Subscription Cancellation
add_action('woocommerce_subscription_status_cancelled', 'restock_inventory_on_subscripadd_action('woocommerce_subscription_status_cancelled', 'adjust_inventory_on_subscription_cancel', 10, 1);
function adjust_inventory_on_subscription_cancel($subscription) {
if (!$subscription) return;
foreach ($subscription->get_items() as $item) {
$product = $item->get_product();
if ($product && $product->managing_stock()) {
$current_stock = $product->get_stock_quantity();
@shameemreza
shameemreza / make-mandatory-coupons-for-all-products-in-woocommerce.php
Created December 10, 2024 04:54
Make mandatory coupons for all products in WooCommerce
add_action( 'woocommerce_check_cart_items', 'mandatory_global_coupon_code' );
function mandatory_global_coupon_code() {
$coupon_code = 'summer2'; // The required coupon code
// Check if the required coupon is applied
$coupon_applied = in_array( strtolower( $coupon_code ), WC()->cart->get_applied_coupons() );
// If the coupon is not applied, prevent checkout
if ( ! $coupon_applied ) {
@shameemreza
shameemreza / hide-out-of-stock-variations-in-woocommerce.php
Created September 26, 2024 09:12
Hide out of stock variations from variable product page in WooCommerce
add_filter( 'woocommerce_variation_is_visible', 'hide_out_of_stock_variations', 10, 4 );
function hide_out_of_stock_variations( $is_visible, $variation_id, $product_id, $variation ) {
if ( ! $variation->is_in_stock() ) {
$is_visible = false;
}
return $is_visible;
}
@shameemreza
shameemreza / woocommerce-remove-shopping-button.php
Created August 22, 2024 09:37
Remove the WooCommerce Continue Shopping Button
// Remove "Product added to cart" message
add_filter( 'wc_add_to_cart_message_html', '__return_null' );
// Remove "Continue Shopping" button
remove_action( 'woocommerce_cart_actions', 'woocommerce_button_continue_shopping', 10 );
@shameemreza
shameemreza / automatically-cancel-orders-in-woocommerce.php
Created July 25, 2024 05:03
Automatically cancel orders after one hour in WooCommerce
add_action( 'woocommerce_order_status_pending', 'wcwiz_cancel_failed_pending_order_event' );
function wcwiz_cancel_failed_pending_order_event( $order_id ) {
if ( ! wp_next_scheduled( 'wcwiz_cancel_failed_pending_order_after_one_hour', array( $order_id ) ) ) {
wp_schedule_single_event( time() + 3600, 'wcwiz_cancel_failed_pending_order_after_one_hour', array( $order_id ) );
}
}
add_action( 'wcwiz_cancel_failed_pending_order_after_one_hour', 'wcwiz_cancel_order' );