format('Y-m-d H:i:s'); return $mydate; } add_action('wp_enqueue_scripts', 'theme_enqueue_styles', 998); function theme_enqueue_styles() { $prefix = function_exists('elessi_prefix_theme') ? elessi_prefix_theme() : 'elessi'; wp_enqueue_style($prefix . '-style', get_template_directory_uri() . '/style.css'); wp_enqueue_style($prefix . '-child-style', get_stylesheet_uri()); } remove_action('wp_head', 'wp_generator'); remove_action('wp_head', 'woo_version'); add_action('wp_head', 'nns_novctag', 1); function nns_novctag() { if ( class_exists( 'Vc_Manager' ) || class_exists( 'Vc_Base' ) ) { remove_action('wp_head', array(visual_composer(), 'addMetaData')); } } function woo_custom_ajax_variation_threshold( $qty, $product ) { return 50; } function defer_parsing_of_js( $url ) { if ( is_user_logged_in() ) return $url; if ( FALSE === strpos( $url, '.js' ) ) return $url; if ( strpos( $url, 'jquery.js' ) || strpos( $url, 'jquery.min.js' ) || strpos($url, 'js_composer_front_min') || strpos($url,'quadpay') || strpos($url, 'add-to-cart') ) { return str_replace( ' src', ' defer src', $url ); } else { return $url; } } function nns_defer_script($tag, $handle, $src) { if ( is_user_logged_in() && is_admin() ) return $tag; $handles = array( 'google-recaptcha', 'affwp-tracking', 'wpcf7-recaptcha', 'swv', 'contact-form-7','themecomplete-epo-product','wc-cart-fragments-js'); $exjquerycf = array('jquery-core', 'jquery-ui-core', 'jquery-cookie', 'jquery-migrate','wc-cart-fragments-js','wc-cart-fragments-js-extra','wc-add-to-cart-bundle','wc-add-to-cart-variation','wc-add-to-cart-variation-js-extra','themecomplete-epo-product'); if(in_array($handle, $exjquerycf)) { $tag = str_replace(''; } } add_filter( 'woocommerce_cart_item_price', 'nns_change_cart_table_price_display', 30, 3 ); function nns_change_cart_table_price_display( $price, $values, $cart_item_key ) { $slashed_price = $values['data']->get_price_html(); $is_on_sale = $values['data']->is_on_sale(); if ( $is_on_sale ) { $price = $slashed_price; } return $price; } add_filter( 'woocommerce_reset_variations_link', '__return_empty_string', 9999 ); function nns_remove_option( $html, $args ) { $show_option_none_text = $args['show_option_none'] ? $args['show_option_none'] : __( 'Choose an option', 'woocommerce' ); $show_option_none_html = ''; $html = str_replace($show_option_none_html, '', $html); return $html; } function woocommerce_button_proceed_to_checkout() { ?> get_id(); $listskus = get_trustpilot_pids($product); if($listskus) { return '
Trustpilot
'; } } remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 ); function nns_add_text_after_product_title(){ the_title( '

', nns_mini_trust().'

' ); } add_action( 'woocommerce_single_product_summary', 'nns_add_text_after_product_title', 5); function nns_trust_reviews() { if ( ! is_product() ) return; global $product; if( ! is_a($product, 'WC_Product') ) { $product = wc_get_product( get_the_id() ); } $pname = $product->get_name(); $listskus = get_trustpilot_pids($product); if($listskus) { } } add_action( 'woocommerce_after_single_product_summary', 'nns_trust_prod', 10); function nns_trust_prod() { global $product; $pid = $product->get_id(); $pname = $product->get_name(); $listskus = get_trustpilot_pids($product); if($listskus) { echo '
Safe Life Defense '.$pname.' Reviews

Trustpilot
'; } } function get_trustpilot_pids($product) { $allowed_pids = array("863390","863386","862344","864956","453","655", "18030", "34410", "17973", "158", "33570", "41489", "175172", "171", "4108", "448051", "590368"); $pid = $product->get_id(); $listskus = ''; if( ($product->is_type( 'simple' ) || $product->is_type('bundle') )){ if($product->is_type('bundle')){ if($pid == '864956') { $listskus = "the-complete-body-armor-bundle"; } } else { $listskus = $product->get_sku(); } } elseif( $product->is_type( 'variable' ) ){ if($pid == "448051") { $listskus = "SLD-PLUS-IV-MTC-B-TAC-B-M-SSA,SLD-PLUS-IV-MTC-B-TAC-B-L,SLD-PLUS-IV-MTC-B-TAC-B-L-SSA,SLD-PLUS-IV-MTC-B-TAC-B-M,SLD-PLUS-IV-MTC-B-TAC-B-2XL"; } else { $skus = array(); $variations = $product->get_children(); foreach ($variations as $variation) { $child = wc_get_product( $variation ); $sku = $child->get_sku(); $skus[] = $sku; } $skus[] = $product->get_sku(); if(count($skus) > 300) { shuffle($skus); $skus = array_slice($skus, 0, 300); } $listskus = implode( ',', $skus ); } } elseif ($product->is_type('bundle')) { if($pid == "590368") { $children = array(33570, 171, 7737, 17387 ); $skus = array(); for($i = 0; $i < count($children); $i++) { $child = wc_get_product( $i ); $childvars = $child->get_children(); foreach ($childvars as $variation) { $child = wc_get_product( $variation ); $sku = $child->get_sku(); $skus[] = $sku; } $skus[] = $child->get_sku(); } } if(count($skus) > 300) { shuffle($skus); $skus = array_slice($skus, 0, 300); } $listskus = implode( ',', $skus ); } return $listskus; } function action_woocommerce_after_cart_contents( ) { echo '
'; } ; add_action( 'woocommerce_after_cart_table', 'action_woocommerce_after_cart_contents', 10, 0 ); add_filter( 'woocommerce_add_to_cart', 'nns_bundle_minicart', 10, 6 ); function nns_bundle_minicart( $cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data) { global $woocommerce; if ( is_admin() ) return; if(WC()->cart->is_empty()) return; $product = wc_get_product( $product_id ); $current_type = $product->get_type(); if($current_type == 'bundle') { sleep(3); add_filter( 'wc_add_to_cart_message_html', '__return_false' ); add_action('wp_footer','nns_add_f_script'); } } function nns_add_f_script() { echo ' '; } function nns_filter_woocommerce_cart_item_visible( $true, $cart_item, $cart_item_key ) { $targeted_ids = array( 851860 ); if ( array_intersect( $targeted_ids, array( $cart_item['product_id'], $cart_item['variation_id'] ) ) ) { $true = false; } return $true; } add_filter( 'woocommerce_cart_item_visible', 'nns_filter_woocommerce_cart_item_visible', 10, 3 ); add_filter( 'woocommerce_widget_cart_item_visible', 'nns_filter_woocommerce_cart_item_visible', 10, 3 ); add_filter( 'woocommerce_checkout_cart_item_visible', 'nns_filter_woocommerce_cart_item_visible', 10, 3 ); function nns_hide_control_product_from_order( $visible, $order_item ) { $product = $order_item->get_product(); if ( $product->get_catalog_visibility() == 'hidden' ) { $visible = false; } return $visible; } add_filter( 'woocommerce_order_item_visible', 'nns_hide_control_product_from_order', 10, 2 ); add_action( 'woocommerce_thankyou', 'nns_register_guests', 9999 ); function nns_register_guests( $order_id ) { $order = wc_get_order( $order_id ); $cphone = preg_replace("/[^0-9]/","", $order->get_billing_phone()); $cphone = preg_replace("/^1/","", $cphone); $email = $order->get_billing_email(); if ( ! email_exists( $email ) && ! username_exists( $email ) ) { $customer_id = wc_create_new_customer( $email, '', '', array( 'first_name' => $order->get_billing_first_name(), 'last_name' => $order->get_billing_last_name(), 'phone' => $cphone, )); if ( is_wp_error( $customer_id ) ) { } wc_update_new_customer_past_orders( $customer_id ); wc_set_customer_auth_cookie( $customer_id ); } else { $user = get_user_by( 'email', $email ); wc_update_new_customer_past_orders( $user->ID ); wc_set_customer_auth_cookie( $user->ID ); } } function action_woocommerce_created_customer( $customer_id, $new_customer_data, $password_generated ) { wc_update_new_customer_past_orders( $customer_id ); file_put_contents("/home/safelife/public_html/link_orders.txt", PHP_EOL.date("Y-m-d H:i:s.").gettimeofday()["usec"]. " --> hook - orders for ".$customer_id." (new) linked via hook", FILE_APPEND); } add_action( 'woocommerce_created_customer', 'action_woocommerce_created_customer', 10, 3 ); function nns_adminfavicon() { echo ''; } add_action('wp_before_admin_bar_render', function() { if(!current_user_can('administrator')) { return; } global $wp_admin_bar; $tooltip = ""; $search_query = ''; if (!empty($_GET['post_type']) && is_numeric($_GET['post_type'] == 'shop_order' )) { $search_query = !empty($_GET['s']) ? $_GET['s'] : ''; if($search_query) { $order = get_post(intval($search_query)); if($order) { wp_redirect(get_edit_post_link($order->ID, '')); exit; } } } else { $tooltip ="Please enter an Order Number"; } $wp_admin_bar->add_menu(array( 'id' => 'admin_bar_shop_order_form', 'title' => '
' )); } ,100); add_filter( 'woocommerce_order_item_name', 'nns_display_order_item_image', 20, 3 ); function nns_display_order_item_image( $item_name, $item, $is_visible ) { global $pagename; if( is_wc_endpoint_url( 'view-order' ) || is_wc_endpoint_url('order-pay') || $pagename == 'track-your-order' || is_order_received_page()) { $product = $item->get_product(); $thumbnail = $product->get_image(array( 80, 80)); if( $product->get_image_id() > 0 ) $item_name = '
' . $thumbnail . '
' . $item_name; } return $item_name; } add_filter('woocommerce_admin_billing_fields', 'woocommerce_require_admin_billing_fields'); function woocommerce_require_admin_billing_fields( $fields ){ $fields['email']['custom_attributes'] = array( 'required' => 'required' ); return $fields; } add_filter( 'woocommerce_shop_order_search_fields', 'billing_phone_search_fields', 10, 1 ); function billing_phone_search_fields( $meta_keys ){ $meta_keys[] = '_billing_phone'; return $meta_keys; } add_action( 'manage_shop_order_posts_custom_column' , 'nns_phone_and_email_column', 50, 2 ); function nns_phone_and_email_column( $column, $post_id ) { if ( $column == 'order_number' ) { global $the_order; if( $phone = $the_order->get_billing_phone() ){ $phone_wp_dashicon = ' '; echo '
' . $phone_wp_dashicon . $phone.''; } if( $email = $the_order->get_billing_email() ){ $em_wp_dashicon = ' '; echo '
' . $em_wp_dashicon.$email . ''; } } } add_filter( 'woocommerce_product_tabs', 'nns_remove_product_tabs', 98 ); function nns_remove_product_tabs( $tabs ) { unset( $tabs['additional_information'] ); return $tabs; } function nns_rename_tabs( $tabs ) { $tabs['description']['title'] = __( 'More Information' ); return $tabs; } add_action( 'woocommerce_archive_description', 'nns_cat_image', 2 ); function nns_cat_image() { if ( is_product_category() ){ global $wp_query; $cat = $wp_query->get_queried_object(); $thumbnail_id = get_term_meta( $cat->term_id, 'thumbnail_id', true ); $image = wp_get_attachment_url( $thumbnail_id ); if ( $image ) { echo '' . $cat->name . ''; } } } function nns_dequeue_plugin_style(){ wp_dequeue_style( 'vertex-connector' ); wp_deregister_style('vertex-connector'); } add_action( 'wp_enqueue_scripts', 'nns_dequeue_plugin_style', 999 ); function nns_vertex_include_static($hook) { $is_vertex = 0; if(false !== stripos($hook,'page_vertex')) { $is_vertex = 1; } else { $is_vertex = 0; } if ($is_vertex < 1) { wp_dequeue_style( 'vertex-connector' ); wp_deregister_style('vertex-connector'); } } add_action( 'admin_enqueue_scripts', 'nns_vertex_include_static', 999 ); add_action( 'woocommerce_before_cart_totals', 'add_custom_checkout_checkbox', 20 ); add_action( 'woocommerce_checkout_before_order_review', 'add_custom_checkout_checkbox', 20 ); function add_custom_checkout_checkbox(){ if( WC()->session->get('custom_fee') ){ $checked = 1; } else { $checked = 0; } if(!is_numeric(WC()->session->get('custom_fee'))) { $checked = 1; } woocommerce_form_field( 'custom_fee', array( 'type' => 'checkbox', 'label' => __('Product Protection'), 'class' => array( 'form-row-wide onoffswitch' ), ), $checked ); } add_filter( 'woocommerce_form_field' , 'remove_order_comments_optional_fields_label', 10, 4 ); function remove_order_comments_optional_fields_label( $field, $key, $args, $value ) { if( 'custom_fee' === $key && ( is_checkout() || is_cart() ) ) { $optional = ' (' . esc_html__( 'optional', 'woocommerce' ) . ')'; $field = str_replace( $optional, '', $field ); } return $field; } add_action( 'wp_footer', 'custom_fee_script' ); function custom_fee_script() { if( ( ( is_cart() || is_checkout() ) && ! is_wc_endpoint_url() ) ) : ?> session->set('custom_fee', ($_POST['custom_fee'] ? '1' : '0') ); echo WC()->session->get('custom_fee'); } die(); } add_action( 'woocommerce_cart_calculate_fees', 'add_remove_custom_fee', 10, 1 ); function add_remove_custom_fee( $cart ) { if ( ( is_admin() && ! defined( 'DOING_AJAX' ) ) ) return; $fee_amount = 0; $subtotal = WC()->cart->get_subtotal(); $fee_amount = ($subtotal * 0.03); $chosen_shipping_method = WC()->session->get('chosen_shipping_methods'); if (strpos($chosen_shipping_method[0], 'international') === false) { $shipus = 1; } else { $shipus = 0; } if( WC()->session->get('custom_fee') ) { if(WC()->customer->get_shipping_country() == "US" ) { $cart->add_fee( __( 'Product Protection', 'woocommerce'), $fee_amount, true); } else { wc_add_notice( 'Product Protection not available for your selected area.', 'error' ); WC()->session->set('custom_fee', '0'); $cart->add_fee( __( 'Product Protection not available', 'woocommerce'), 0, false); } } if(!is_numeric(WC()->session->get('custom_fee'))) { if(WC()->customer->get_shipping_country() == "US") { $cart->add_fee( __( 'Product Protection', 'woocommerce'), $fee_amount, true); } else { wc_add_notice( 'Product Protection not available for your selected area.', 'error' ); WC()->session->set('custom_fee', '0'); $cart->add_fee( __( 'Product Protection not available', 'woocommerce'), 0, false); } } } add_action( 'woocommerce_admin_order_data_after_order_details', 'nns_add_prp_checkbox' ); function nns_add_prp_checkbox( $order ){ ?>

Product Protection Edit

get_meta( 'add_prp' ); ?>

Add PRP?

'add_prp', 'label' => 'Auto-Add PRP?', 'value' => $add_prp, 'style' => 'width:16px', 'wrapper_class' => 'form-field-wide' ) ); ?>
add_order_note( "PRP status changed" ,0, true); } add_action( 'woocommerce_new_order', 'nns_check_prp1', 1, 2 ); function nns_check_prp( $order_id, $order ) { $orderfile = '/home/newsafel/public_html/wp-content/uploads/nns-orderfile.txt'; $order = wc_get_order( $order_id ); foreach ( $order->get_items() as $item_id => $item ) { $product_name = $item->get_name(); $item_type = $item->get_type(); $orderstring = "v1a - ORDER ID: ".$order_id." - INAME: ".$product_name . " - ITYPE: ".$item_type."\n"; file_put_contents($orderfile, $orderstring, FILE_APPEND); } foreach( $order->get_items('fee') as $item_id => $item_fee ){ $fee_name = $item_fee->get_name(); $fee_total = $item_fee->get_total(); $fee_total_tax = $item_fee->get_total_tax(); $feestring = "v1b - ORDER ID: ".$order_id." - INAME: ".$fee_name . " - ITYPE: fee -- ITOTAL: ".$fee_total. " - IFTAX: ". $fee_total_tax."\n"; file_put_contents($orderfile, $feestring, FILE_APPEND); if($fee_name == "Product Protection") { update_post_meta( $order_id, 'add_prp','yes' ); } } } function nns_check_prp1( $order_id, $order ) { $orderfile = '/home/newsafel/public_html/wp-content/uploads/nns-orderfile.txt'; foreach ( $order->get_items() as $item_id => $item ) { $product_name = $item->get_name(); $item_type = $item->get_type(); $orderstring = "v3a - ORDER ID: ".$order_id." - INAME: ".$product_name . " - ITYPE: ".$item_type."\n"; file_put_contents($orderfile, $orderstring, FILE_APPEND); } foreach( $order->get_items('fee') as $item_id => $item_fee ){ $fee_name = $item_fee->get_name(); $fee_total = $item_fee->get_total(); $fee_total_tax = $item_fee->get_total_tax(); $feestring = "v3b - ORDER ID: ".$order_id." - INAME: ".$fee_name . " - ITYPE: fee -- ITOTAL: ".$fee_total. " - IFTAX: ". $fee_total_tax."\n"; file_put_contents($orderfile, $feestring, FILE_APPEND); if($fee_name == "Product Protection") { update_post_meta( $order_id, 'add_prp','yes' ); } } } add_action( 'woocommerce_cart_calculate_fees', 'add_cart_fee', 9,1 ); function add_cart_fee($cart) { if (is_admin() && !defined('DOING_AJAX')) { return; } $taxregion = array('CO'); $chosen_shipping_method = WC()->session->get('chosen_shipping_methods')[0]; if( in_array( $cart->get_customer()->get_shipping_state(), $taxregion ) ) { $surcharge = 0.27; $cart->add_fee( __('Retail Delivery CO', 'woocommerce'), $surcharge, false ); } } add_action( 'wp_footer', 'nns_update_checkout_totals' ); function nns_update_checkout_totals() { ?> = 2 ) return; $percentage = 0.03; $add_prp = $order->get_meta('add_prp'); $order_subtotal = $order->get_subtotal(); if(!$order_subtotal || wc_format_decimal($order_subtotal) <= 0) { $fee_amount = 0; } else { $fee_amount = wc_format_decimal( $order_subtotal * $percentage ); } $fee_data = array( 'name' => __('Product Protection'), 'amount' => $fee_amount, 'tax_status' => 'taxable', 'tax_class' => '' ); $retail_fee_data = array( 'name' => __('Retail Delivery Fee'), 'amount' => 0.27, 'tax_status' => 'taxable', 'tax_class' => 'CORDF' ); $fee_items = $order->get_fees(); $prp = 0; if($add_prp != "") { if( empty($fee_items) ){ $item = new WC_Order_Item_Fee(); $item->set_name( $fee_data['name'] ); $item->set_amount( $fee_data['amount'] ); $item->set_tax_class($fee_data['tax_class']); $item->set_tax_status($fee_data['tax_status']); $item->set_total($fee_data['amount']); $order->add_item( $item ); $item->save(); } else { foreach ( $fee_items as $item_id => $item ) { if( $item->get_name() === $fee_data['name'] ) { $prp++; $item->set_amount($fee_data['amount']); $item->set_tax_class($fee_data['tax_class']); $item->set_tax_status($fee_data['tax_status']); $item->set_total($fee_data['amount']); $item->save(); if($prp > 1) { $order->remove_item( $item_id); $order->calculate_totals(); $order->save(); } } } if($prp < 1) { $item = new WC_Order_Item_Fee(); $item->set_name( $fee_data['name'] ); $item->set_amount( $fee_data['amount'] ); $item->set_tax_class($fee_data['tax_class']); $item->set_tax_status($fee_data['tax_status']); $item->set_total($fee_data['amount']); $order->add_item( $item ); $item->save(); } } } else { if( !empty($fee_items) ){ foreach ( $fee_items as $item_id => $item ) { if( $item->get_name() === $fee_data['name'] ) { $order->remove_item( $item_id); $order->calculate_totals(); $order->save(); } } } } if($order->get_shipping_state() == "CO") { $x = 0; foreach ($fee_items as $key => $fee) { if($fee->get_name() === $retail_fee_data['name']) { $x++; if($x > 1) { $order->remove_item($key); $order->calculate_totals(); $order->save(); } } } if($x < 1) { $rfee = new WC_Order_Item_Fee(); $rfee->set_name( $retail_fee_data['name']); $rfee->set_amount( $retail_fee_data['amount'] ); $rfee->set_tax_status($retail_fee_data['tax_status']); $rfee->set_total($retail_fee_data['amount']); $order->add_item( $rfee ); $order->save(); } } else { foreach ($fee_items as $key => $fee) { if($fee->get_name() === $retail_fee_data['name']) { $order->remove_item($key); $order->calculate_totals(); $order->save(); } } } } function disable_wp_emojicons() { remove_action( 'admin_print_styles', 'print_emoji_styles' ); remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ); remove_action( 'wp_print_styles', 'print_emoji_styles' ); remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' ); remove_filter( 'the_content_feed', 'wp_staticize_emoji' ); remove_filter( 'comment_text_rss', 'wp_staticize_emoji' ); add_filter( 'tiny_mce_plugins', 'disable_emojicons_tinymce' ); } add_action( 'init', 'disable_wp_emojicons' ); function disable_emojicons_tinymce( $plugins ) { if ( is_array( $plugins ) ) { return array_diff( $plugins, array( 'wpemoji' ) ); } else { return array(); } } add_action('nasa_subtotal_free_shipping', 'elessi_subtotal_free_shipping'); add_action('woocommerce_widget_shopping_cart_total', 'elessi_subtotal_free_shipping', 20); if (!function_exists('elessi_subtotal_free_shipping')) : function elessi_subtotal_free_shipping($return = false) { $content = ''; if (!NASA_WOO_ACTIVED || !class_exists('WooCommerce_Advanced_Free_Shipping') || !function_exists('WAFS')) { return $content; } if( WC()->cart->has_discount( 'shipfree' ) || WC()->cart->has_discount( 'freeship') || WC()->customer->get_shipping_country() != 'US') { return; } $wafs = WAFS(); if (!isset($wafs->was_method)) { $wafs->wafs_free_shipping(); } $wafs_method = isset($wafs->was_method) ? $wafs->was_method : null; if (!$wafs_method || $wafs_method->enabled === 'no') { return $content; } $wafs_posts = get_posts(array( 'post_status' => 'publish', 'post_type' => 'wafs' )); if (!$wafs_posts || count($wafs_posts) < 1) { return $content; } $value = 0; foreach ($wafs_posts as $wafs_post) { $condition_groups = get_post_meta($wafs_post->ID, '_wafs_shipping_method_conditions', true); if (!$condition_groups || count($condition_groups) !== 1) { continue; } $condition_group = reset($condition_groups); if (!$condition_group || count($condition_group) !== 1) { continue; } foreach ($condition_group as $condition) { if ($condition['condition'] !== 'subtotal_ex_tax' || $condition['operator'] !== '>=' || !$condition['value']) { continue; } if (!$value || $value > $condition['value']) { $value = $condition['value']; } } } $subtotalCart = WC()->cart->cart_contents_total; $taxes = WC()->cart->get_total_tax(); $shipping = WC()->cart->get_cart_shipping_total(); $total = WC()->cart->get_cart_total(); $spend = 0; $content_cond = ''; $content_desc = ''; if ($subtotalCart < $value) { $spend = $value - $subtotalCart; $per = intval(($subtotalCart/$value)*100); $allowed_html = array( 'strong' => array(), 'a' => array( 'class' => array(), 'href' => array(), 'title' => array() ), 'span' => array( 'class' => array() ), 'br' => array() ); $content_desc .= '
' . sprintf( wp_kses(__('You are %s away from FREE SHIPPING! Continue Shopping', 'elessi-theme'), $allowed_html), wc_price($spend), esc_url(get_permalink(wc_get_page_id('shop'))) ) . '
'; } else { $per = 100; $content_desc .= '
'; $content_desc .= ''; $content_desc .= esc_html__("Congratulations! You've earned free shipping.", 'elessi-theme'); $content_desc .= '
'; } $class_cond = 'nasa-total-condition-wrap'; $content_cond .= '
' . '
' . '' . $per . '%' . '
' . '
'; $content .= '
'; $content .= $content_cond; $content .= '
'; $content .= $content_desc; if (!$return) { echo $content; return; } return $content; } endif; add_action('woocommerce_cart_contents', 'elessi_subtotal_free_shipping_in_cart'); if (!function_exists('elessi_subtotal_free_shipping_in_cart')) : function elessi_subtotal_free_shipping_in_cart() { $content = elessi_subtotal_free_shipping(true); if ($content !== '') { echo '' . $content . ''; } } endif; add_filter( 'woocommerce_package_rates', 'nns_remove_free_shipping', 100, 2 ); function nns_remove_free_shipping( $rates, $package ) { if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return $rates; $country = WC()->customer->get_shipping_country(); $cart_subtotal = $order_total = WC()->cart->get_subtotal(); $rateval = 'advanced_free_shipping'; $rateid = 'shipping_method_0_advanced_free_shipping'; $regfree = 'free_shipping:56'; $regfreeid = 'shipping_method_0_free_shipping56'; $upsnxt = 'ups:31:02'; $ups2nd = 'ups:31:13'; foreach( $package['contents'] as $cart_item ) { $variation_id = $cart_item['variation_id']; if( 0 != $variation_id) { $variation_obj = new WC_Product_variation($variation_id); $stock = $variation_obj->get_stock_quantity(); } else { $product_id = $cart_item['product_id']; $product_obj = new WC_Product($product_id); $stock = $product_obj->get_stock_quantity(); } if( $stock <= 0 ){ unset($rates[$upsnxt]); unset($rates[$ups2nd]); break; } } if ( array_key_exists($upsnxt, $rates ) && in_array(date('N'), [5,6,7]) ) { unset($rates[$upsnxt]); } if ( array_key_exists($ups2nd, $rates ) && in_array(date('N'), [5,6,7]) ) { unset($rates[$ups2nd]); } if($country != "US") { foreach( $rates as $rate_id => $rate_val ) { if ( 'advanced_free_shipping' === $rate_val->get_method_id() ) { unset( $rates[ $rate_id ] ); } } } if($country == "US" && $cart_subtotal >= 500) { foreach( $rates as $rate_id => $rate_val ) { if ( 'free_shipping' === $rate_val->get_method_id() ) { unset( $rates[ $rate_id ] ); } } } return $rates; } add_filter( 'woocommerce_package_rates' , 'nns_sort_shipping_services_by_cost', 10, 2 ); function nns_sort_shipping_services_by_cost( $rates, $package ) { if ( ! $rates ) return $rates; $rate_cost = array(); foreach( $rates as $rate ) { $rate_cost[] = $rate->cost; } array_multisort( $rate_cost, $rates ); return $rates; } function nns_glove_sizer() { global $product; if($product) { $pid = $product->get_id(); $gloveprods = array(862344); $multicams = array(859026, 858938,33570); if(in_array($pid, $gloveprods)) { echo ' '; } if(in_array($pid, $multicams) || is_product_category()) { echo " "; } if(is_product_category() || 'bundle' === $product->get_type()) { echo " "; } } } add_action('wp_footer','nns_glove_sizer'); add_action('admin_head', 'nns_admin_styles'); function nns_admin_styles() { echo ''; } add_action('admin_head', 'nns_hide_delete_note_from_edit_order'); function nns_hide_delete_note_from_edit_order() { echo ''; } function nns_register_partial_refund_order_status() { register_post_status( 'wc-partial-refund', array( 'label' => 'Partially Refunded', 'public' => true, 'show_in_admin_status_list' => true, 'show_in_admin_all_list' => true, 'exclude_from_search' => false, 'label_count' => _n_noop( 'Partially Refunded (%s)', 'Partially Refunded (%s)' ) ) ); } add_action( 'init', 'nns_register_partial_refund_order_status' ); function nns_add_partial_refund_to_order_statuses( $order_statuses ) { $new_order_statuses = array(); foreach ( $order_statuses as $key => $status ) { $new_order_statuses[ $key ] = $status; if ( 'wc-processing' === $key ) { $new_order_statuses['wc-partial-refund'] = 'Partially Refunded'; } } return $new_order_statuses; } add_filter( 'wc_order_statuses', 'nns_add_partial_refund_to_order_statuses' ); function nns_register_bc_import_order_status() { register_post_status( 'wc-bc-imported', array( 'label' => 'BC Imported', 'public' => true, 'show_in_admin_status_list' => true, 'show_in_admin_all_list' => true, 'exclude_from_search' => false, 'label_count' => _n_noop( 'BigCommerce Import (%s)', 'BigCommerce Import (%s)' ) ) ); } add_action( 'init', 'nns_register_bc_import_order_status' ); function nns_add_bc_import_to_order_statuses( $order_statuses ) { $new_order_statuses = array(); foreach ( $order_statuses as $key => $status ) { $new_order_statuses[ $key ] = $status; if ( 'wc-processing' === $key ) { $new_order_statuses['wc-bc-imported'] = 'BC Imported'; } } return $new_order_statuses; } add_filter( 'wc_order_statuses', 'nns_add_bc_import_to_order_statuses' ); function nns_register_pending_verification_order_status() { register_post_status( 'wc-verification', array( 'label' => 'Pending Verification', 'public' => true, 'show_in_admin_status_list' => true, 'show_in_admin_all_list' => true, 'exclude_from_search' => false, 'label_count' => _n_noop( 'Pending Verification (%s)', 'Pending Verification (%s)' ) ) ); } add_action( 'init', 'nns_register_pending_verification_order_status' ); function nns_add_pending_verification_to_order_statuses( $order_statuses ) { $new_order_statuses = array(); foreach ( $order_statuses as $key => $status ) { $new_order_statuses[ $key ] = $status; if ( 'wc-processing' === $key ) { $new_order_statuses['wc-verification'] = 'Pending Verification'; } } return $new_order_statuses; } add_filter( 'wc_order_statuses', 'nns_add_pending_verification_to_order_statuses' ); add_action( 'woocommerce_order_details_after_order_table', 'nns_ny_order_status' ); function nns_ny_order_status( $order_id ){ if( ! $order_id ) return; $nytxt = ""; $cat_in_order = false; $order = wc_get_order( $order_id ); $cat_in_order = nns_get_order_category($order_id); if($order->get_shipping_state() == "NY" && $cat_in_order) { if($order->get_status() == "pending" || $order->get_status() == 'processing' || $order->get_status() == 'pending-payment') { $mailsent = $order->get_meta( 'nyorder' ); $paidxtime = $order->get_meta('_date_paid'); if ((!$mailsent || $mailsent < 1) && $paidxtime >= '1657004400') { $order->update_status( 'wc-verification', "Order pending verification - NY state #".__LINE__ ); $order->update_status( 'verification', "Order pending verification - NY state #".__LINE__); $order->update_meta_data( 'nyorder', 1); } } $nytxt .= "Your order is pending verification due to NY regulations.
We will call you within 72 hours or you can reach out to us at info@safelifedefense.com


"; add_filter('woocommerce_thankyou_order_received_text', 'nns_change_order_received_text', 10, 2 ); } echo $nytxt; } function nns_change_order_received_text( $str, $order ) { $state = $order->get_shipping_state(); if($state == "NY") { $str .= "
Your order is pending verification due to NY regulations.
We will call you within 72 hours or you can reach out to us at info@safelifedefense.com

"; } return $str; } add_action( 'woocommerce_payment_complete', 'nns_nystatus_for_paid_orders' ); function nns_nystatus_for_paid_orders( $order_id ) { $order = wc_get_order( $order_id ); $newstate = ""; $cat_in_order = false; $cat_in_order = nns_get_order_category($order_id); if($order->get_shipping_state() == "NY" && $cat_in_order) { if($order->get_status() != 'verification') { $order->update_status( 'verification', "Order pending verification - NY state #".__LINE__ ); $order->update_status( 'wc-verification', "Order pending verification - NY state #".__LINE__ ); } $newstate = $order->get_status(); if($newstate != 'verification') { $order->update_status( 'verification', "Order pending verification - NY state #".__LINE__ ); } } } add_action('woocommerce_order_status_changed', 'nns_nystatus_changes', 10, 3); function nns_nystatus_changes($order_id, $old_status, $new_status) { $order = wc_get_order($order_id); $verified = false; $cat_in_order = false; $cat_in_order = nns_get_order_category($order_id); if($order->get_shipping_state() == "NY" && $cat_in_order) { if($old_status == 'verification' && $new_status == 'processing') { $order_notes = wc_get_order_notes([ 'order_id' => $order_id, ]); foreach ($order_notes as $order_note){ if ($order_note->content == "SLDOV"){ $verified = true; break; } } if(!$verified) { $order->update_status( 'verification', "Order not yet verified. Cannot change status." ); } else { $mailer = WC()->mailer()->get_emails(); $mailer['WC_Email_Customer_Processing_Order']->trigger( $order_id ); } } } else { if($new_status == 'processing') { $mailer = WC()->mailer()->get_emails(); $mailer['WC_Email_Customer_Processing_Order']->trigger( $order_id ); } } } add_filter( 'woocommerce_email_actions', 'custom_email_actions', 20, 1 ); function custom_email_actions( $action ) { $actions[] = 'woocommerce_order_status_wc-verification'; return $actions; } add_action( 'woocommerce_order_status_wc-verification', array( WC(), 'send_transactional_email' ), 10, 1 ); add_action('woocommerce_order_status_verification', 'nns_status_verification_notification', 20, 2); function nns_status_verification_notification( $order_id, $order ) { if( ! $order->has_status('verification') ) return; $mailsent = $order->get_meta( 'nyorder' ); if (!$mailsent || $mailsent <= 1) { $mailer = WC()->mailer()->get_emails(); $mailer['WC_Email_Customer_Processing_Order']->trigger( $order_id ); if($order->get_shipping_state() == "NY") { $order->update_meta_data( 'nyorder', 2); } } } function nns_order_user_role_filter() { global $typenow, $wp_query; if ( in_array( $typenow, wc_get_order_types( 'order-meta-boxes' ) ) ) { $user_role = ''; $user_roles = array( 'guest' => 'Guest' ); foreach ( get_editable_roles() as $key => $values ) { $user_roles[ $key ] = $values['name']; } if ( ! empty( $_GET['_user_role'] ) ) { $user_role = sanitize_text_field( $_GET['_user_role'] ); } ?>is_main_query() || empty( $_GET['_user_role'] ) || $_GET['post_type'] !== 'shop_order' ) { return; } if ( $_GET['_user_role'] != 'guest' ) { $ids = get_users( array( 'role' => sanitize_text_field( $_GET['_user_role'] ), 'fields' => 'ID' ) ); $ids = array_map( 'absint', $ids ); } else { $ids = array( 0 ); } $query->set( 'author__in', $ids ); if ( empty( $ids ) ) { $query->set( 'posts_per_page', 0 ); } } add_filter( 'pre_get_posts', 'nns_order_user_role_posts_where' ); add_filter( 'manage_edit-shop_order_columns', 'nns_register_CSR_column', 10, 1 ); function nns_register_CSR_column( $columns ) { $columns['cs_agent'] = 'CSR/Agent'; return $columns; } add_action( 'manage_shop_order_posts_custom_column', 'nns_display_CSR_user', 10, 1 ); function nns_display_CSR_user( $column ) { global $post; if ( 'cs_agent' === $column ) { $creator = $post->post_author; $creator_name = get_the_author_meta( 'display_name', $creator ); if($creator != 1) { echo "$creator_name"; } } } add_filter('woe_get_order_fields', function ($fields) { $fields['user_name'] = array( 'label' => 'Agent Name', 'colname' => 'Agent Name', 'checked' => 1 ); return $fields; } ); add_filter('woe_get_order_value_user_name', function ($value,$order, $field) { $oid = $order->get_id(); $product_post_object = get_post( $oid ); $vendor_id = $product_post_object->post_author; $user_id = get_user_by('id',$vendor_id); $author_display_name = $user_id ->display_name; return $author_display_name ; } , 10, 3); function change_order_item_meta_value($value, $meta, $item) { $orderItemId = $item->get_id(); $orderItem = new WC_Order_Item_Product($orderItemId); $id = $orderItem->get_product_id(); $variationId = $orderItem->get_id(); $product = wc_get_product($id); if(!$product) { return $value; } $type = $product->get_type(); if($type == 'simple') { $id = $product->get_id(); if(get_field('custom_backorder_message', $id)) { $text = get_field('custom_backorder_message', $id); } else { $text = get_field('product_backorder_message', 'options'); } } elseif($type == 'variable') { $parentId = $orderItem->get_product_id(); $id = $orderItem->get_product_id(); if(get_post_meta($id, '_text_field', true ) && get_post_meta($id, '_text_field', true) != ' ') { $text = get_post_meta($id, '_text_field', true ); } else { if(get_field('custom_backorder_message', $parentId)) { $text = get_field('custom_backorder_message', $parentId); } else { $text = get_field('product_backorder_message', 'options'); } } } if('backordered' === strtolower($meta->key)) { $value = '

' . $text . '

'; } return $value; } add_filter( 'woocommerce_order_item_display_meta_value', 'change_order_item_meta_value', 20, 3 ); if( function_exists('acf_add_options_page') ) { acf_add_options_page(); acf_set_options_page_title('Site Options'); } add_action( 'woocommerce_product_after_variable_attributes', 'variation_settings_fields', 10, 3 ); add_action( 'woocommerce_save_product_variation', 'save_variation_settings_fields', 10, 2 ); function variation_settings_fields( $loop, $variation_data, $variation ) { woocommerce_wp_text_input( array( 'id' => '_text_field[' . $variation->ID . ']', 'label' => __( 'Backorder Message', 'woocommerce' ), 'placeholder' => '', 'desc_tip' => 'true', 'description' => __( 'Enter the custom backorder message here.', 'woocommerce' ), 'value' => get_post_meta( $variation->ID, '_text_field', true ) ) ); } function save_variation_settings_fields( $post_id ) { $text_field = $_POST['_text_field'][ $post_id ]; update_post_meta( $post_id, '_text_field', esc_attr( $text_field ) ); } add_action( 'woocommerce_before_single_product', 'move_variations_single_price', 1 ); function move_variations_single_price(){ global $product, $post; if ( $product->is_type( 'variable' ) ) { remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 ); add_action( 'woocommerce_before_add_to_cart_button', 'replace_variation_single_price', 10 ); } } function replace_variation_single_price(){ global $product; $exitems = array(851418,852446,852648, 852650); $prices = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'max', true ) ); $price = $prices[0] !== $prices[1] ? sprintf( __( '%1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] ); $prices = array( $product->get_variation_regular_price( 'min', true ), $product->get_variation_regular_price( 'max', true ) ); sort( $prices ); $saleprice = $prices[0] !== $prices[1] ? sprintf( __( '%1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] ); if ( $price !== $saleprice && $product->is_on_sale() ) { $price = '' . $saleprice . $product->get_price_suffix() . ' ' . $price . $product->get_price_suffix() . ''; } ?> get_id(), $exitems)) { echo '

'.$price.'

'.$price.'
'; } } add_action('woocommerce_single_product_summary', 'nns_quadpay', 21); function nns_quadpay() { global $product; $saleprod = ''; if( $product->get_id() == 545759 ) return; if ($product->is_on_sale()) { $saleprod = ' ins'; } echo '
'; } function nns_variation_messages(){ echo '
'; } add_filter( 'woocommerce_get_availability', 'display_variation_availability_count', 99, 2 ); function display_variation_availability_count( $args, $product ) { $product_id = $product->is_type('variation') ? $product->get_parent_id() : $product->get_id(); $parent_id = $product->get_parent_id(); if($parent_id == '17387' || $parent_id == '171' || $parent_id == '7737' || $parent_id == '33570' || $parent_id == '545431') { $stock = $product->get_stock_quantity(); $bomsg = "In Stock - PID: ".$product_id . " - ".$stock; $aclass = $args['class']; return $args; } } function xdisplay_variation_availability_count( $availability, $product ) { if ( $product->managing_stock() && $product->is_type('variation') ) { $availability = __("Stock: ") . $product->get_stock_quantity(); return $availability; } } add_filter( 'nasa_fake_in_cart_content', 'nns_text_mods', 23); function nns_text_mods($cart_data) { global $nasa_opt; $min = isset($nasa_opt['min_fake_in_cart']) && (int) $nasa_opt['min_fake_in_cart'] ? (int) $nasa_opt['min_fake_in_cart'] : 1; $max = isset($nasa_opt['max_fake_in_cart']) && (int) $nasa_opt['max_fake_in_cart'] ? (int) $nasa_opt['max_fake_in_cart'] : 20; $in_cart = rand($min, $max); $fake_in_cart_data = '
'; $fake_in_cart_data .= ' '; $fake_in_cart_data .= sprintf( esc_html__('%s people have this in their cart', 'nasa-core'), $in_cart ); $fake_in_cart_data .= '
'; echo $fake_in_cart_data; } function nns_patch_stuff() { global $product; if($product) { $pid = $product->get_id(); $vests = array(851829); $bundles = array(); $patchitems = array(851974, 851947, 851834, 850879 ); if(in_array($pid, $vests)) { echo " "; } elseif (in_array($pid, $patchitems)) { echo " "; } } } function nns_cards_stuff() { if(is_product() || is_product_category() || is_page()) { echo" "; } else { } } add_action('wp_footer','nns_cards_stuff'); add_action('woocommerce_new_order', 'nns_woocommerce_new_order', 10, 2); function nns_woocommerce_new_order( $order_id, $order ) { } function nns_display_order_field_in_admin( $order ){ ?>
' . __( 'BC Order ID' ) . ': ' . get_post_meta( $order->get_id(), 'bcorderid', true ) . ' - '; echo '' . __( 'BC Order Total' ) . ': ' . get_post_meta( $order->get_id(), 'bcordertotal', true ) . ' - '; echo '' . __( 'BC Tax Total' ) . ': ' . get_post_meta( $order->get_id(), 'bcordertax', true ) . '

'; ?>
is_type( 'variable' )){ $va = $product->get_variation_attributes(); echo "
";
 var_dump( $va );
 echo "
"; $vas = []; foreach ( $product->get_attributes() as $attribute ) { echo "

attr: ".$attribute['name']; if ( isset( $attribute['is_taxonomy'] ) && $attribute['is_taxonomy']) { $terms = wp_get_post_terms( $product_id, $attribute['name'] ) ; foreach ( $terms as $term ) { if ( in_array( $term->slug, $va[ $attribute['name'] ] ) ) { if ( ! isset( $vas[$attribute['name']] ) ) { $vas[$attribute['name']] = []; } $vas[$attribute['name']][] = $term->term_id; } } } } foreach ($vas as $tax => $vals) { wp_set_post_terms( $product_id, $vals, $tax ); } } } include 'functions-codup.php';