This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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' ); | |
This file contains hidden or 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
// Show company instead of name in the orders list | |
add_filter( 'woocommerce_admin_order_buyer_name', function( string $buyer, WC_Order $order ): string { | |
$company = trim( $order->get_billing_company() ); | |
if ( empty( $company ) ) { | |
return $buyer; | |
} else { | |
return $company; | |
} | |
}, 10, 2 ); |
This file contains hidden or 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_processing', 'change_role_on_purchase', 10, 2 ); | |
add_action( 'woocommerce_order_status_completed', 'change_role_on_purchase', 10, 2 ); | |
function change_role_on_purchase( $order_id, $order ) { | |
$user = $order->get_user(); // Get the WP_User Object | |
// Check for "customer" user roles only | |
if( is_a( $user, 'WP_User' ) && in_array( 'customer', (array) $user->roles ) ) { | |
// Remove WooCommerce "customer" role | |
$user->remove_role( 'customer' ); |
This file contains hidden or 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
function wc_empty_cart_logout() { | |
if( function_exists('WC') ){ | |
WC()->cart->empty_cart(); | |
} | |
} | |
add_action('wp_logout', 'wc_empty_cart_logout'); |
This file contains hidden or 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( 'setted_transient', 'mmx_wc_product_loop_transient', 50, 3 ); | |
function mmx_wc_product_loop_transient( $transient, $value, $expiration ){ | |
$pos = strpos( $transient, 'wc_product_loop_' ); | |
if ( $pos !== false && $expiration == 2592000 ) { | |
set_transient( $transient, $value, DAY_IN_SECONDS ); | |
} | |
} |
This file contains hidden or 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( 'pre_http_request', 'sport_shooting_depot_mock_square_background_check', 10, 3 ); | |
function sport_shooting_depot_mock_square_background_check( $preemt, $args, $url ) { | |
if ( $url !== 'YOUR_SITE_URL_HERE/wp-admin/admin-ajax.php?action=wc_square_background_sync_test' ) { | |
return false; | |
} | |
return array( | |
'body' => '[TEST_LOOPBACK]', | |
'response' => array( | |
'code' => '200 OK' |