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 |
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 enable_google_apple_pay_for_event_tickets($available_gateways) { | |
if (is_admin()) return $available_gateways; | |
global $product; | |
if (!$product) return $available_gateways; | |
// Check if the product is an event ticket | |
$is_event_ticket = has_term('event', 'product_cat', $product->get_id()); | |
if ($is_event_ticket) { |
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_product_options_general_product_data', 'custom_woocommerce_product_fields'); | |
function custom_woocommerce_product_fields() { | |
woocommerce_wp_text_input([ | |
'id' => '_custom_field', | |
'label' => __('Custom Field', 'woocommerce'), | |
'desc_tip' => 'true', | |
'description' => __('Enter the value for the custom field.', 'woocommerce'), | |
]); | |
} |
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
// Step 1: Add a meta box for store stock field | |
function custom_store_stock_meta_box() { | |
add_meta_box( | |
'custom_store_stock_meta_box', // Meta box ID | |
'Store Stock', // Title | |
'render_custom_store_stock_meta_box', // Callback function to render the meta box content | |
'product', // Post type (product for WooCommerce products) | |
'side', // Context (side, normal, advanced) | |
'default' // Priority (high, core, default, low) | |
); |
NewerOlder