codescribblr
5/10/2017 - 1:26 PM

Theme overrides for Bridge WooCommerce theme.

Theme overrides for Bridge WooCommerce theme.

/**
 *Reduce the strength requirement on the woocommerce password.
 *
 * Strength Settings
 * 3 = Strong (default)
 * 2 = Medium
 * 1 = Weak
 * 0 = Very Weak / Anything
 */
add_filter( 'woocommerce_min_password_strength', 'jrwdev_reduce_woocommerce_min_strength_requirement' );
function jrwdev_reduce_woocommerce_min_strength_requirement( $strength ) {
    return 0;
}

// Now remove the javascript password strength meter
add_action( 'wp_print_scripts', 'jrwdev_wc_ninja_remove_password_strength', 100 );
function jrwdev_wc_ninja_remove_password_strength() {
    if ( wp_script_is( 'wc-password-strength-meter', 'enqueued' ) ) {
        wp_dequeue_script( 'wc-password-strength-meter' );
    }
}

// Do not allow PO boxes in shipping address.
add_action('woocommerce_after_checkout_validation', 'jrwdev_deny_pobox_postcode');
function jrwdev_deny_pobox_postcode( $posted ) {
  global $woocommerce;
  
  $address  = ( isset( $posted['shipping_address_1'] ) ) ? $posted['shipping_address_1'] : $posted['billing_address_1'];
  $postcode = ( isset( $posted['shipping_postcode'] ) ) ? $posted['shipping_postcode'] : $posted['billing_postcode'];
  
  $replace  = array(" ", ".", ",");
  $address  = strtolower( str_replace( $replace, '', $address ) );
  $postcode = strtolower( str_replace( $replace, '', $postcode ) );

  if ( strstr( $address, 'pobox' ) || strstr( $postcode, 'pobox' ) ) {
    wc_add_notice( "Sorry, we don't ship to PO BOX addresses." );
  }
}

// Require acknowledgement field
add_filter( 'woocommerce_after_checkout_validation', 'jrwdev_require_wc_acknowledgement_field', 1001 );
function jrwdev_require_wc_acknowledgement_field( $posted ) {
    global $woocommerce;
    if ( !$posted['ack_accept'] ) {
        wc_add_notice( "You must agree to our buyer acknowledgement." );
    }
}

add_action( 'woocommerce_after_checkout_form', 'jrwdev_checkout_adjustments', 10, 1);
function jrwdev_checkout_adjustments($checkout){
    ?>
<style>
.wc-terms-and-conditions {float:none;}
#print_quote {
    float:right;
    position: relative;
    right: 10px;
    line-height: 31px;
}
#print_disclaimer {
    float:right;
    position: relative;
    right: 20px;
    line-height: 31px;
    font-size: 15px;
}
@media print {
    .woocommerce-info {display: none !important;}
    .wc-terms-and-conditions {display: none;}
    #customer_details {display: none !important;}
    #checkoutpopupform {display: none !important;}
}
</style>
<script>
function jrwdev_layout_fixes(){
	var terms = jQuery('.wc-terms-and-conditions').eq(0);
    terms.css({'float':'none'}).addClass('form-row-wide');
    jQuery('.wc-terms-and-conditions').remove();
    terms.prependTo('#customer_details .col-1');
    if(!jQuery('#customer_details .col-1 .wc-terms-and-conditions')){
        
    }
    var $printButton = jQuery(document.createElement('button'));
    var $printDisclaimer = jQuery(document.createElement('span'));
    $printButton
        .addClass('button alt')
        .text('Print Quote')
        .attr('id', 'print_quote')
        .insertAfter('#place_order');
    $printButton.on('click', function(e){
        e.preventDefault();
        window.print();
    });
    $printDisclaimer
        .text('You must enter shipping information for an accurate quote.')
        .attr('id', 'print_disclaimer')
        .insertAfter('#print_quote');

    //Handle Form layout issues
    jQuery('#customer_details').append('<div class="clear"></div>');
    jQuery('#customer_details').append(jQuery('.woocommerce-additional-fields'));
    jQuery('#ack_header_field').addClass('form-row-wide');
    jQuery('#ack_text_field').addClass('form-row-wide');
    jQuery('#ack_accept_field').addClass('form-row-wide');
    jQuery('#s_h_field').addClass('form-row-wide');
    jQuery('.form-row-last').after('<div class="clear"></div>');
    jQuery('#ship-to-different-address').css({'padding-top': '29px'});
    if(jQuery('#payment_method_invoice').is(':checked')){
    	jQuery('#place_order').val('Request Invoice');
    }
}
jQuery('.woocommerce-checkout').on('updated_checkout', function(){
    jrwdev_layout_fixes();
});
jQuery(document).ready(function(){
    jrwdev_layout_fixes();
});
jQuery(document).on('change', '#payment_method_invoice', function(){
	if(jQuery(this).is(':checked')){
		jQuery('#place_order').val('Request Invoice');
	}
})
</script>
    <?php
}

add_action('wp_head', 'jrwdev_custom_cart_icon', 100);
function jrwdev_custom_cart_icon() {
    ?>
    <style>
        .shopping_cart_header .header_cart {
            background-image: url(/wp-content/themes/bridge/img/cart-icon.png) !important;
            background-size: 90%;
        }
        .shopping_cart_header .header_cart .header_cart_span {
            display: none;
        }
    </style>
    <?php
}

add_filter('woocommerce_available_payment_gateways', 'jrwdev_filter_gateways', 1);
function jrwdev_filter_gateways($gateways){
	$user_id = get_current_user_id();
    global $woocommerce;
    
	if(!$user_id || !get_field('invoice_system_access', 'user_'.$user_id)){
	    //Remove a specific payment option
	    error_log("\r\nRegular Customer\r\n");
		error_log(print_r($gateways, true));
	    unset($gateways['invoice']);
	    return $gateways;
	} else {
		error_log("\r\nInvoice Customer\r\n");
		error_log(print_r($gateways, true));
		return $gateways;
	}
}

add_action('woocommerce_account_dashboard', 'jrwdev_modify_dashboard', 10);
function jrwdev_modify_dashboard(){
	global $woocommerce;
	$cart_url = $woocommerce->cart->get_cart_url();
	echo '<p style="text-align: center; margin-top: 40px;"><a href="'.$cart_url.'" class="qbutton large alt">Retrieve your current order here</a></p>';
}