// Check if the current domain is america.frostsellconsultingweb.com
if ($_SERVER['HTTP_HOST'] === 'america.frostsellconsultingweb.com') {
// Add this code to your theme's functions.php file or a custom plugin
//***************************************Cartflows Change Product Name******************************************************************************
// Define a custom function to change the product name
function custom_change_product_name($item_name, $cart_item, $cart_item_key) {
// Check the product ID and change the name accordingly
switch ($cart_item['product_id']) {
case '11':
$item_name = '1 Month Subscription';
break;
case '12':
$item_name = '3 Month Subscription';
break;
case '13':
$item_name = '6 Month Subscription';
break;
case '14':
$item_name = '12 Months Subscription';
break;
case '15':
$item_name = '2x1 Month Subscription';
break;
case '16':
$item_name = '2x3 Month Subscription';
break;
case '17':
$item_name = '2x6 Month Subscription';
break;
case '18':
$item_name = '2x12 Months Subscription';
break;
case '19':
$item_name = '3x1 Month Subscription';
break;
case '20':
$item_name = '3x3 Month Subscription';
break;
case '21':
$item_name = '3x6 Month Subscription';
break;
case '23':
$item_name = '3x12 Months Subscription';
break;
case '24':
$item_name = '4x1 Month Subscription';
break;
case '25':
$item_name = '4x3 Month Subscription';
break;
case '26':
$item_name = '4x6 Month Subscription';
break;
case '27':
$item_name = '4x12 Months Subscription';
break;
}
return $item_name;
}
// Hook into the 'woocommerce_cart_item_name' filter to apply the custom function
add_filter('woocommerce_cart_item_name', 'custom_change_product_name', 10, 3);
//***************************************DirectCoupon******************************************************************************
function my_woocommerce_apply_cart_coupon_in_url() {
// Return early if WooCommerce or sessions aren't available.
if (!function_exists('WC') || !WC()->session) {
return;
}
// Return if there is no coupon in the URL, otherwise set the variable.
if (empty($_REQUEST['coupon'])) {
return;
} else {
$coupon_code = esc_attr($_REQUEST['coupon']);
}
// Set a session cookie to remember the coupon if they continue shopping.
WC()->session->set_customer_session_cookie(true);
// Apply the coupon to the cart if necessary.
if (!WC()->cart->has_discount($coupon_code)) {
// WC_Cart::add_discount() sanitizes the coupon code.
WC()->cart->add_discount($coupon_code);
}
}
add_action('wp_loaded', 'my_woocommerce_apply_cart_coupon_in_url', 30);
add_action('woocommerce_add_to_cart', 'my_woocommerce_apply_cart_coupon_in_url');
//***************************************Show Ordre Summary******************************************************************************
add_filter('cartflows_show_mobile_order_summary_collapsed', '__return_false');
//***************************************Hide Product "has been added to your cart"******************************************************************************
add_filter('wc_add_to_cart_message_html', '__return_false');
//***************************************Free insted of 0$"******************************************************************************
add_filter('woocommerce_get_price_html', 'ecommercehints_change_zero_price_display', 10, 2);
function ecommercehints_change_zero_price_display($price, $product)
{
if (empty($product->get_price()) || $product->get_price() == 0) { // If price is not entered or set to 0
$price = __('Free', 'woocommerce');
}
return $price;
}
//***************************************You cannot add another __ to your cart"******************************************************************************
add_filter('woocommerce_add_to_cart_sold_individually_found_in_cart', 'bbloomer_no_message_if_already_found_in_cart');
function bbloomer_no_message_if_already_found_in_cart($found)
{
if ($found) {
throw new Exception();
}
return $found;
}
//***************************************reset cart"******************************************************************************
add_filter('woocommerce_add_to_cart_validation', 'wtwh_only_one_in_cart', 9999, 2);
function wtwh_only_one_in_cart($passed, $added_product_id)
{
wc_empty_cart();
return $passed;
}
//***************************************woocommerce_custom_email_per_product_depending_on_product_id"******************************************************************************
function woocommerce_custom_email_per_product_depending_on_product_id( $email_heading, $order ) {
global $woocommerce;
$items = $order->get_items();
foreach ( $items as $item ) {
// Check the product ID and change the name accordingly
switch ($item['product_id']) {
case '11':
$item['name']= '1 Month Subscription';
break;
case '12':
$item['name']= '3 Month Subscription';
break;
case '13':
$item['name']= '6 Month Subscription';
break;
case '14':
$item['name']= '12 Months Subscription';
break;
case '15':
$item['name']= '2x1 Month Subscription';
break;
case '16':
$item['name']= '2x3 Month Subscription';
break;
case '17':
$item['name']= '2x6 Month Subscription';
break;
case '18':
$item['name']= '2x12 Months Subscription';
break;
case '19':
$item['name']= '3x1 Month Subscription';
break;
case '20':
$item['name']= '3x3 Month Subscription';
break;
case '21':
$item['name']= '3x6 Month Subscription';
break;
case '23':
$item['name']= '3x12 Months Subscription';
break;
case '24':
$item['name']= '4x1 Month Subscription';
break;
case '25':
$item['name']= '4x3 Month Subscription';
break;
case '26':
$item['name']= '4x6 Month Subscription';
break;
case '27':
$item['name']= '4x12 Months Subscription';
break;
}
return $email_heading;
}
}
add_filter( 'woocommerce_email_heading_customer_processing_order', 'woocommerce_custom_email_per_product_depending_on_product_id', 10, 5 );
}
© 2023 Quttera Ltd. All rights reserved.