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_completed', 'track_completed_orders_101', 10, 1); | |
function track_completed_orders_101($order_id) { | |
$order = wc_get_order($order_id); | |
$user_id = $order->get_user_id(); | |
if ($user_id) { | |
$completed_orders = get_user_meta($user_id, '_completed_orders_count', true); | |
$completed_orders = $completed_orders ? $completed_orders + 1 : 1; | |
update_user_meta($user_id, '_completed_orders_count', $completed_orders); | |
} |
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
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40); | |
add_action('woocommerce_single_product_summary', 'custom_display_limited_product_categories', 40); | |
function custom_display_limited_product_categories() { | |
global $product; | |
$categories = wp_get_post_terms( $product->get_id(), 'product_cat', array('orderby' => 'name', 'order' => 'ASC', 'number' => 1)); // Limit to 3 categories | |
if ( $categories && !is_wp_error( $categories ) ) { | |
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 WooCommerce before shop loop to display subcategories | |
add_action('woocommerce_before_shop_loop', 'display_woo_subcategories', 15); | |
function display_woo_subcategories() { | |
if (!is_product_category()) { | |
return; | |
} | |
$term_id = get_queried_object_id(); | |
$taxonomy_name = 'product_cat'; | |
$termchildren = get_term_children($term_id, $taxonomy_name); |
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_cart_calculate_fees', 'buy_ten_get_two_free', 10, 1 ); | |
function buy_ten_get_two_free( $cart ){ | |
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return; | |
// Set HERE your targeted variable products IDs | |
$targeted_product_ids = array( 185 ); | |
$each_n_items = 10; // Number of items required to get a free one | |
$free_items_count = 2; // Number of free items to give | |
$discount = 0; // Initializing |
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('wp_head', 'rl_add_preload', 1); | |
function rl_add_preload() { | |
global $product; | |
if (is_product() && isset($product)) { | |
$image = wp_get_attachment_image_src($product->get_image_id(), "edit"); | |
if ($image && is_array($image) && isset($image[0])) { | |
echo PHP_EOL . '<link rel="preload" as="image" href="' . esc_url($image[0]) . '">' . PHP_EOL; |
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
function remove_quantity_field_for_sold_individually_products() { | |
if ( is_product() ) { | |
global $product; | |
if ( is_object( $product ) && $product->is_sold_individually() ) { | |
// Remove the quantity field | |
remove_action( 'woocommerce_before_add_to_cart_quantity', 'woocommerce_template_single_add_to_cart', 10 ); | |
remove_action( 'woocommerce_after_add_to_cart_quantity', 'woocommerce_template_single_add_to_cart', 10 ); | |
} |
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_item_meta_end', 'display_custom_data_in_emails', 10, 4 ); | |
function display_custom_data_in_emails( $item_id, $item, $order, $bool ) { | |
$terms = wp_get_post_terms( $item->get_product_id(), 'product_cat', array( 'fields' => 'names' ) ); | |
echo "<br><small>" . implode(', ', $terms) . "</small>"; | |
} | |
add_action( 'woocommerce_after_order_itemmeta', 'custom_admin_order_itemmeta', 15, 3 ); |
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_single_product_summary', 'display_discount_table', 20 ); | |
function display_discount_table() { | |
global $product; | |
if ( ! $product->is_type( 'simple' ) ) { | |
return; | |
} | |
$discounts = [ |
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_package_rates', 'custom_woocommerce_available_shipping_methods', 100); | |
function custom_woocommerce_available_shipping_methods($rates) { | |
$free_shipping_minimum = 100; // Set your minimum cart total for free shipping here | |
$cart_total = WC()->cart->get_subtotal(); | |
if ($cart_total >= $free_shipping_minimum) { | |
foreach ($rates as $rate_id => $rate) { | |
if ('free_shipping' === $rate->method_id) { | |
$free_shipping_rate = $rates[$rate_id]; | |
$rates = array($rate_id => $free_shipping_rate); |
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 a flat rate fee for a specific product | |
add_action( 'woocommerce_cart_calculate_fees', 'add_flat_rate_fee_for_specific_product_v1', 10, 1 ); | |
function add_flat_rate_fee_for_specific_product_v1( $cart ) { | |
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) { | |
return; | |
} | |
$product_id = 123; // Replace with the ID of your specific product | |
$flat_rate_fee = 10; // Replace with your desired flat rate fee |
NewerOlder