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
// Hook into the 'woocommerce_checkout_process' action | |
add_action( 'woocommerce_checkout_process', 'restrict_gateway_orders_per_day' ); | |
function restrict_gateway_orders_per_day() { | |
// Set the maximum number of orders allowed per day | |
$max_orders_per_day = 20; | |
// Get the current date | |
$current_date = date( 'Y-m-d' ); |
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
remove_action('woocommerce_before_shop_loop', 'woocommerce_result_count', 20); | |
remove_action('woocommerce_after_shop_loop', 'woocommerce_result_count', 20); |
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_add_to_cart_redirect', 'wp_get_referer' ); |
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_payment_complete_order_status', 'wc_auto_complete_paid_order', 10, 3 ); | |
function wc_auto_complete_paid_order( $status, $order_id, $order ) { | |
if ( $order->get_payment_method() === 'stripe' ) { | |
$status = 'completed'; | |
} | |
return $status; | |
} |
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_before_order_itemmeta', 'add_admin_order_item_product_permalink', 10, 2 ); | |
function add_admin_order_item_product_permalink( $item_id, $item ) { | |
if( $item->get_type() !== 'line_item' ) | |
return; | |
$product = $item->get_product(); | |
// Add a hidden input field with the product permalink | |
printf( '<input type="hidden" name="product-permalink" value="%s">', esc_url($product->get_permalink())); | |
} |
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
// Utility function: check if product category handle zero rate tax class | |
function is_zero_rate_tax_class( $product_id ) { | |
return has_term( array(28, 29, 30, 32, 34), 'product_cat', $product_id ); | |
} | |
// Conditional function: Check if the customer is from specific country code | |
function is_from_targeted_country( $country_code ) { | |
return WC()->customer->get_billing_country() === $country_code; | |
} |
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_before_shop_loop_item_title', 'show_product_loop_backorder_badge', 5 ); | |
function show_product_loop_backorder_badge(){ | |
global $product; | |
if ( $product->is_on_backorder() ) { | |
printf('<span class="on-backorder">%s</span>', esc_html__('Out of stock', 'woocommerce')); | |
} | |
} |
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 customer's full name to My Account page in WooCommerce | |
function display_customer_full_name() { | |
// Get the current user's ID | |
$user_id = get_current_user_id(); | |
// Get the user's first and last name | |
$first_name = get_user_meta($user_id, 'first_name', true); | |
$last_name = get_user_meta($user_id, 'last_name', true); | |
// Display the full name |
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
// Define a custom schedule time for Cron schedules tasks | |
add_filter( 'cron_schedules','hourly_cron_schedule' ); | |
function hourly_cron_schedule( $schedules ) { | |
if ( ! isset( $schedules["hourly"] ) ) { | |
$schedules["hourly"] = array( | |
'interval' => HOUR_IN_SECONDS, | |
'display' => __( 'Hourly' ) | |
); | |
} | |
return $schedules; |