This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' ); | |
NewerOlder