View difference between Paste ID: 0xBVavFQ and wqqW9Ez4
SHOW: | | - or go back to the newest paste.
1
<?php
2
3
// Various saveinstitute debug helper
4
// Leave FALSE for live site
5
define("SI_DEBUG", false);
6
7
global $save_globals;
8
$save_globals['search_link'] = true;
9
$save_globals['toggle_mobile'] = true;
10
11
add_image_size('product-small', 9999, 100, false);
12
13
// Load our custom stylesheets
14
add_action( 'wp_enqueue_scripts', 'enqueue_theme_styles', 999 );
15
function enqueue_theme_styles() {
16
  define( 'THEME_VERSION', filemtime( get_stylesheet_directory() . '/style.css' ) );
17
18
  // Styles
19
  wp_enqueue_style( 'linearicons', get_stylesheet_directory_uri().'/css/lnr.css' );
20
  wp_enqueue_style( 'save-style', get_stylesheet_directory_uri().'/style.css', array(), THEME_VERSION );
21
  wp_enqueue_style( 'mmenu', get_stylesheet_directory_uri().'/css/jquery.mmenu.all.css' );
22
23
  // Scripts
24
  wp_enqueue_script('hover-intent', get_stylesheet_directory_uri().'/js/jquery.hoverIntent.min.js', array('jquery'), '1.8.0', TRUE); // Hover Intent
25
  wp_enqueue_script('mmenu', get_stylesheet_directory_uri().'/js/jquery.mmenu.all.min.js', array('jquery'), '5.6.5', TRUE); // Mobile Menu (mmenu)
26
  wp_enqueue_script('matchheight', get_stylesheet_directory_uri().'/js/jquery.matchheight.js', array('jquery'), '0.7', TRUE); // Core Args
27
	wp_enqueue_script('saveinstitute', get_stylesheet_directory_uri().'/js/jquery.save.js', array('jquery'), THEME_VERSION, TRUE); // Core Args
28
29
  // Shepherd
30
  wp_register_style( 'shepherd', get_stylesheet_directory_uri().'/css/shepherd-theme-arrows.css' );
31
	wp_register_script('tether', get_stylesheet_directory_uri().'/js/tether.min.js', array('jquery'), '0.6.5', TRUE);
32
	wp_register_script('shepherd', get_stylesheet_directory_uri().'/js/shepherd.min.js', array('tether'), '1.8.1', TRUE);
33
}
34
35
// Replace the SAVOY default scripts with some of our own
36
add_action( 'wp_enqueue_scripts', 'sob_replace_scripts', 20 ); // Replace footer scripts
37
function sob_replace_scripts() {
38
    // Shop Filters (remove the scroll on ajax load)
39
    wp_register_script( 'nm-shop-filters', get_stylesheet_directory_uri().'/js/jquery.save-shop-filters.js', array( 'jquery', 'nm-shop' ), NM_THEME_VERSION );
40
41
    // Add to cart (remove the widget panel disapearing after adding duplicate order)
42
    wp_register_script( 'nm-shop-add-to-cart', get_stylesheet_directory_uri().'/js/jquery.save-shop-add-to-cart.js', array( 'jquery', 'nm-shop' ), NM_THEME_VERSION );
43
}
44
45
class SOB_Sublevel_Walker extends Walker_Nav_Menu {
46
    function start_lvl( &$output, $depth = 0, $args = array() ) {
47
        $indent = str_repeat("\t", $depth);
48
        $output .= "\n$indent<div class='sub-menu-wrap'><ul class='submenu wrap nm-header-row'>\n";
49
    }
50
    function end_lvl( &$output, $depth = 0, $args = array() ) {
51
        $indent = str_repeat("\t", $depth);
52
        $output .= "$indent</ul></div>\n";
53
    }
54
}
55
56
add_action('si_after_checkout','si_do_after_checkout');
57
function si_do_after_checkout() {
58
  ?>
59
  <div class="testimonials">
60
    <blockquote>
61
      <p>"You have changed our lives in so many ways for the better. Thanks to you, my severe osteoporosis is completely reversed through the Save Our Bones program alone."</p>
62
      <cite>Helen S.</cite>
63
    </blockquote>
64
    <blockquote>
65
      <p>"I’m so happy I found your information on the web. It’s so great that you provide us with the knowledge and information to help ourselves without resorting to dangerous drugs."</p>
66
      <cite>Rivkah G.</cite>
67
    </blockquote>
68
  </div>
69
  <div class="satisfaction">
70
    <p><img class="alignleft" src="<?php echo get_stylesheet_directory_uri(); ?>/images/badge.png" height="150px" width="150px" alt="SATISFACTION 100% GUARANTEED" />Your success is our goal. That's why the Save Institute offers an unprecedented no questions asked 60 day guarantee. If you're not happy for any reason, simply contact us to request your full refund.</p>
71
  </div>
72
  <hr />
73
  <h5>Exceptional 24/7 Customer Service</h5>
74
  <p>We're here for you. If you have problems with your order or questions about the program, just shoot us an email at support@saveinstitute.com. You'll receive a personal response within 24-48 hours.</p>
75
  <hr />
76
  <h5>You’re In Good Company</h5>
77
  <p>You're joining a growing community of more than 200,000 Savers who have found success with the Save Institute since 2007.</p>
78
  <hr />
79
  <h5>We Protect Your information And Your Privacy</h5>
80
  <p>Our order process is completely secure - the entire transaction will take place on a secure server using 128 Bit SSL technology. And we promise never to sell or give away any of the information you entrust us with to other companies.</p>
81
  <?php
82
}
83
84
// Remove payments placement (add it back in the template)
85
remove_action( 'woocommerce_checkout_order_review', 'woocommerce_checkout_payment', 20 );
86
add_action( 'woocommerce_checkout_shipping', 'woocommerce_checkout_payment', 20 );
87
add_action('woocommerce_checkout_shipping', 'si_amazon_button', 19);
88
function si_amazon_button() {
89
  //echo '<div class="wc_payment_method payment_method_amazon"><div id="pay_with_amazon"></div></div>';
90
}
91
92
// Place order text
93
add_filter( 'woocommerce_order_button_text', create_function( '', 'return "Click Here To Complete Your Order";' ) );
94
95
add_action( 'woocommerce_before_single_product', 'nm_header_return');
96
function nm_header_return() {wc_get_template_part( 'content', 'product_nm_header' );}
97
98
// Tag List
99
if ( ! function_exists( 'nm_tag_menu' ) ) {
100
    function nm_tag_menu() {
101
      $terms = get_terms( 'product_tag');
102
      if ($terms != '') { ?>
103
        <ul>
104
        <?php foreach ($terms as $term) { ?>
105
          <li class="tag-<?php echo $term->slug; ?>"><a href="<?php echo home_url(); ?>/product-tag/<?php echo $term->slug; ?>"><?php echo $term->name; ?></a></li>
106
        <?php } ?>
107
      </ul>
108
      <?php }
109
    }
110
}
111
112
// Product in cart helper
113
function woo_in_cart($product_id) {
114
    global $woocommerce;
115
116
    foreach($woocommerce->cart->get_cart() as $key => $val ) {
117
        $_product = $val['data'];
118
119
        if($product_id == $_product->id ) {
120
            return true;
121
        }
122
    }
123
124
    return false;
125
}
126
127
// New Menus
128
register_nav_menus( array(
129
  'health-topics'   => __(  'Health Topics',   'sob' ),
130
  'product-types'   => __( 'Product Types',    'sob' ),
131
  'members-menu'    => __( 'Members Menu',     'sob' ),
132
  'dashboard-menu'    => __( 'Dashboard Page Menu', 'sob' ),
133
  'footer-menu'    => __( 'Footer Menu', 'sob' ),
134
) );
135
136
// Remove WooCommerce Updater
137
remove_action('admin_notices', 'woothemes_updater_notice');
138
139
add_filter( 'woocommerce_billing_fields', 'si_move_checkout_email_field', 10, 1 );
140
function si_move_checkout_email_field( $address_fields ) {
141
  // [priority] field isn't working for some reason, so lets just move the email to the start of the array
142
  $address_fields = array('billing_email' => $address_fields['billing_email']) + $address_fields;
143
  return $address_fields;
144
}
145
146
add_filter( 'woocommerce_checkout_fields' , 'woo_remove_billing_checkout_fields' );
147
/**
148
 * Remove unwanted checkout fields
149
 *
150
 * @return $fields array
151
*/
152
function woo_remove_billing_checkout_fields( $fields ) {
153
154
	if( is_admin() ) {
155
		return $fields;
156
	}
157
158
    if( woo_cart_has_virtual_product() == true ) {
159
      unset($fields['billing']['billing_company']);
160
      unset($fields['billing']['billing_address_1']);
161
      unset($fields['billing']['billing_address_2']);
162
      unset($fields['billing']['billing_city']);
163
      unset($fields['billing']['billing_postcode']);
164
      unset($fields['billing']['billing_country']);
165
      unset($fields['billing']['billing_state']);
166
      unset($fields['billing']['billing_phone']);
167
      unset($fields['order']['order_comments']);
168
      unset($fields['billing']['billing_address_2']);
169
      unset($fields['billing']['billing_postcode']);
170
      unset($fields['billing']['billing_company']);
171
      unset($fields['billing']['billing_city']);
172
    }
173
174
    return $fields;
175
}
176
/**
177
 * Check if the cart contains virtual product
178
 *
179
 * @return bool
180
*/
181
function woo_cart_has_virtual_product() {
182
183
  global $woocommerce;
184
185
  // By default, no virtual product
186
  $has_virtual_products = false;
187
188
  // Default virtual products number
189
  $virtual_products = 0;
190
191
  // Get all products in cart
192
  $products = $woocommerce->cart->get_cart();
193
194
  // Loop through cart products
195
  foreach( $products as $product ) {
196
197
    // Get product ID and '_virtual' post meta
198
    $product_id = $product['product_id'];
199
    $is_virtual = get_post_meta( $product_id, '_virtual', true );
200
201
    // Update $has_virtual_product if product is virtual
202
    if( $is_virtual == 'yes' )
203
      $virtual_products += 1;
204
  }
205
206
  if( count($products) == $virtual_products )
207
    $has_virtual_products = true;
208
209
  return $has_virtual_products;
210
}
211
212
// force the "securely save to account" checkbox to default to checked
213
function wc_auth_net_cim_save_payment_method_default_checked( $html, $form ) {
214
	if ( empty( $html ) || $form->tokenization_forced() ) {
215
		return $html;
216
	}
217
218
	return str_replace( 'type="checkbox"', 'type="checkbox" checked="checked"', $html );
219
}
220
add_filter( 'wc_authorize_net_cim_credit_card_payment_form_save_payment_method_checkbox_html', 'wc_auth_net_cim_save_payment_method_default_checked', 10, 2 );
221
222
// unrequre the phone
223
add_filter( 'woocommerce_billing_fields', 'wc_npr_filter_phone', 10, 1 );
224
function wc_npr_filter_phone( $address_fields ) {
225
$address_fields['billing_phone']['required'] = false;
226
return $address_fields;
227
}
228
229
// Add shop header
230
add_action('si_before_shop_content','si_homepage_header', 1);
231
function si_homepage_header() {
232
  if (is_shop()) {
233
    echo '<div class="featured-header"><div class="nm-row"><h2>Your Health.<br/>Our Research.</h2><h4 class="tag">Natural Evidence-Based Solutions That Work</h4></div></div>';
234
  }
235
}
236
237
// Change shop placeholder image
238
add_action('init', 'change_shop_image');
239
function change_shop_image() {
240
  global $nm_globals;
241
  $nm_globals['product_placeholder_image'] = apply_filters( 'nm_shop_placeholder_img_src', get_stylesheet_directory_uri() . '/images/placeholder.png' );
242
}
243
244
// Add general member functions
245
include_once('member/member.php');
246
247
// Add shortcodes
248
include_once('shortcodes/shortcodes.php');
249
include_once('shortcodes/shortcodes-admin.php');
250
251
// Check if is a parent or child of parent
252
function is_tree($pid) {      // $pid = The ID of the page we're looking for pages underneath
253
	global $post;         // load details about this page
254
	if(is_page()&&($post->post_parent==$pid||is_page($pid)))
255
               return true;   // we're at the page or at a sub page
256
	else
257
               return false;  // we're elsewhere
258
};
259
260
/**
261
 *Reduce the strength requirement on the woocommerce password.
262
 *
263
 * Strength Settings
264
 * 3 = Strong (default)
265
 * 2 = Medium
266
 * 1 = Weak
267
 * 0 = Very Weak / Anything
268
 */
269
function reduce_woocommerce_min_strength_requirement( $strength ) {
270
    return 0;
271
}
272
add_filter( 'woocommerce_min_password_strength', 'reduce_woocommerce_min_strength_requirement' );
273
add_filter('password_hint', function() { return 'Hint: The password should be at least eight characters long. To make it stronger, use upper and lower case letters, numbers, and symbols like ! " ? $ % ^ &amp; ).'; });
274
275
// Remove "Order Again"
276
remove_action( 'woocommerce_order_details_after_order_table', 'woocommerce_order_again_button' );
277
278
// Moive coupon stuff
279
add_action('woocommerce_checkout_shipping', function() {
280
  global $nm_globals;
281
282
  if ( isset( $nm_globals['checkout_coupon_message'] ) ) :
283
  ?>
284
  <ul class="nm-checkout-login-coupon nm-checkout-login-coupon-inner"><li><?php wc_print_notice( $nm_globals['checkout_coupon_message'], 'notice' ); ?></li></ul>
285
  <?php endif;
286
287
}, 15);
288
289
// Flowplayer Scripts and Styles on video pages
290
add_action('wp_enqueue_scripts', 'flowplayer_stuff', 1);
291
function flowplayer_stuff() {
292
  if (get_field('m3u8_embed'))  {
293
    wp_enqueue_style( 'flowplayer-skin', get_stylesheet_directory_uri().'/css/skin/skin.css' );
294
    wp_enqueue_script('flowplayer-hls', 'https://cdnjs.cloudflare.com/ajax/libs/hls.js/0.10.1/hls.light.min.js', array('jquery'), '0.10.1', FALSE);
295
    wp_enqueue_script('flowplayer-main', get_stylesheet_directory_uri().'/js/flowplayer.min.js', array('jquery'), '7.2.6', FALSE);
296
  }
297
}
298
299
function my_woocommerce_add_error( $error ) {
300
  return str_replace('An account is already registered with your email address. Please log in.',sprintf( __( 'An account is already registered with your email address. <a class="showlogin2" href="#nm-checkout-login-form" style="text-decoration: underline; display: inline-block !important;"> Please Login</a> and come back to checkout. Forgot Password? <a style="display: inline-block !important; text-decoration: underline;" href="'.wp_lostpassword_url().'">Click here to get a new one. </a>', 'woocommerce' ) ),$error);
301
}
302
add_filter( 'woocommerce_add_error', 'my_woocommerce_add_error' );
303
304
// Currency plugin adder
305
add_action('woocommerce_widget_shopping_cart_before_buttons', 'si_woo_curr_converter', 15);
306
add_action('woocommerce_single_product_summary', 'si_woo_curr_converter', 15 );
307
add_action('woocommerce_checkout_order_review', 'si_woo_curr_converter', 15 );
308
add_action('woocommerce_proceed_to_checkout', 'si_woo_curr_converter', 1 );
309
function si_woo_curr_converter() {
310
  echo '<div class="curr-converter">'.do_shortcode( '[woocommerce_currency_converter currency_codes="USD, CAD, EUR, GBP, AUD"]' ).'</div>';
311
}
312
313
// Change billing details text on checkout page (woocoomerce)
314
add_filter( 'gettext', 'si_billing_field_strings', 20, 3 );
315
function si_billing_field_strings( $translated_text, $text, $domain ) {
316
    switch ( $translated_text ) {
317
        case 'Billing details' :
318
            $translated_text = __( 'Customer information', 'woocommerce' );
319
            break;
320
    }
321
    return $translated_text;
322
}
323
324
// Tag 1 Click Upsells with WP Fusion
325
function wpf_send_upsell_details( $order, $event, $result ) {
326
327
	$order_id = $order->get_id();
328
329
	wp_fusion()->integrations->woocommerce->woocommerce_apply_tags_checkout( $order_id, true, true );
330
331
}
332
333
add_action( 'wc_1cu_combined_order_payment_processed', 'wpf_send_upsell_details', 10, 3 );