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 / set-the-maximum-order-limits-per-day-by-paypal-payment.php
Last active July 7, 2024 14:39
Set the maximum order limits per day by PayPal payment gateway in WooCommerce
// 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' );
@shameemreza
shameemreza / remove-the-search-results-count-in-woocommerce.php
Created July 6, 2024 18:05
Remove the search results count in WooCommerce.
remove_action('woocommerce_before_shop_loop', 'woocommerce_result_count', 20);
remove_action('woocommerce_after_shop_loop', 'woocommerce_result_count', 20);
@shameemreza
shameemreza / rename-frequently-bought-together-add-to-cart-button.php
Created July 6, 2024 17:59
Rename the frequently bought together button in WooCommerce.
add_filter( 'woocommerce_product_single_add_to_cart_text', 'filter_product_single_add_to_cart_text', 20, 2 );
function filter_product_single_add_to_cart_text( $add_to_cart_text, $product ) {
// Define your targeted product IDs in the array below
$targeted_ids = array(22246, 22241, 22227, 22039, 22009, 22004, 21999, 21991);
if (in_array($product->get_id(), $targeted_ids)) {
$add_to_cart_text = __("PRE ORDER", "woocommerce");
}
return $add_to_cart_text;
}
@shameemreza
shameemreza / remove-add-to-cart-url-parameter-after-a-product-has-been-added-to-the-cart.php
Last active July 6, 2024 17:51
Remove add to cart URL parameter after a product has been added to the cart in WooCommerce.
add_filter( 'woocommerce_add_to_cart_redirect', 'wp_get_referer' );
@shameemreza
shameemreza / autocomplete-paid-orders-for-specific-payment-gateway.php
Created July 6, 2024 17:48
Autocomplete paid orders for specific payment gateway in WooCommerce.
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;
}
@shameemreza
shameemreza / change-order-items-admin-product-link-to-the-product-permalink-front.php
Created July 6, 2024 17:47
Change the order items admin product link to the product permalink frontend in WooCommerce.
@shameemreza
shameemreza / exclude-product-taxes-based-on-product-categories-and-country.php
Created July 6, 2024 17:45
Exclude product taxes based on product categories and country in WooCommerce.
// 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;
}
@shameemreza
shameemreza / show-out-of-stock-label-in-catalogue-when-product-is-on-backorder.php
Created July 6, 2024 17:43
Show out of stock label in catalogue when product is on backorder in Woocommerce.
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'));
}
}
@shameemreza
shameemreza / display-customers-full-name-in-my-account.php
Created July 6, 2024 17:42
Display the customer’s full name in the My Account page in WooCommerce.
// 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
@shameemreza
shameemreza / auto-complete-processing-orders-with-bookings-which-start-date-is-passed.php
Created July 6, 2024 17:41
Auto complete processing orders with bookings which start date is passed in WooCommerce.
// 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;