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
//Hide the Bundle When a product is Out of Stock
add_filter( 'woocommerce_product_is_visible', 'hide_bundle_when_required_product_is_out_of_stock', 10, 2 );
function hide_bundle_when_required_product_is_out_of_stock( $visible, $product_id ) {
$product = wc_get_product( $product_id );
// Check if the product is a bundle
if ( $product && $product->is_type( 'bundle' ) ) {
$bundled_items = $product->get_bundled_items();
# Inside AutomateWoo, use the variable: {custom_function.aw_get_gift_card_code} to include the gift card code in the email.
# The gift card codes are stored as order item meta data.
function aw_get_gift_card_code( $workflow ) {
$order = $workflow->data_layer()->get_order();
foreach ( $order->get_items() as $item ) {
if ( $item->get_product()->is_type( 'gift-card' ) ) {
$gift_card_code = $item->get_meta( '_wc_gc_giftcard_code', true );
if ( ! empty( $gift_card_code ) ) {
return $gift_card_code;
add_filter( 'woocommerce_email_classes', function( $emails ) {
if ( isset( $emails['WC_GC_Email_Gift_Card_Received'] ) ) {
unset( $emails['WC_GC_Email_Gift_Card_Received'] );
}
return $emails;
}, 20 );
@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 ) {