Last active
February 1, 2019 20:32
-
-
Save jimboobrien/d09003f42bb44fc79a99 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/*****************************************************************************/ | |
/**************VISIONQUEST WOOCOMMERCE CUSTOM FUNCTIONS***********************/ | |
/******************************************************************************/ | |
remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10); | |
remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10); | |
add_action('woocommerce_before_main_content', 'my_theme_wrapper_start', 10); | |
add_action('woocommerce_after_main_content', 'my_theme_wrapper_end', 10); | |
function my_theme_wrapper_start() { | |
echo '<div class="container"><div class="sixteen columns pageWrapper">'; ?> | |
<div class="sixteen columns pageContent offset-by-one alpha"> | |
<!--<div class="nine columns pageContent offset-by-one alpha">--> | |
<div id="woo-content-custom"> | |
<? } | |
function my_theme_wrapper_end() { | |
echo '</div></div>'; | |
?> | |
<ul class="sidebar five columns omega clearfix"> | |
<?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar("Pages")) ; ?> | |
</ul> | |
<? echo '</div></div>'; | |
} | |
add_theme_support( 'woocommerce' ); | |
/* | |
* wc_remove_related_products | |
* | |
* Clear the query arguments for related products so none show. | |
* Add this code to your theme functions.php file. | |
*/ | |
function wc_remove_related_products( $args ) { | |
return array(); | |
} | |
add_filter('woocommerce_related_products_args','wc_remove_related_products', 10); | |
/*========================================================== | |
This is for the little cart in the primary navigation | |
===========================================================*/ | |
/* add_filter('wp_nav_menu_items','add_last_nav_item', 10, 2 ); | |
function add_last_nav_item($items, $args) { | |
global $woocommerce; | |
if ( $args->theme_location == 'primary' ) { | |
return $items .= '<li class="menu-item-cart-item"><div class="log-in-out-link">'. <?php echo $loginout = wp_loginout($_SERVER['REQUEST_URI'], false ); ?> .'</div></li>'; | |
} | |
return $items; | |
} */ | |
// this should only ever fire on non-cached pages (so it SHOULD fire | |
// whenever we add to cart / update cart / etc | |
function update_cart_total_cookie() | |
{ | |
global $woocommerce; | |
$cart_total = $woocommerce->cart->cart_contents_count; | |
setcookie('woocommerce_cart_total', $cart_total, 0, '/'); | |
} | |
add_action('init', 'update_cart_total_cookie'); | |
add_filter('add_to_cart_fragments', 'woocommerce_header_add_to_cart_fragment'); | |
function woocommerce_header_add_to_cart_fragment( $fragments ) { | |
global $woocommerce; | |
ob_start(); | |
?> | |
<a class="cart-contents" href="<?php echo $woocommerce->cart->get_cart_url(); ?>" ><?php echo sprintf(_n('%d', '%d', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);?></a> | |
<?php | |
$fragments['a.cart-contents'] = ob_get_clean(); | |
return $fragments; | |
} | |
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' ); | |
function custom_override_checkout_fields( $fields ) { | |
unset($fields['billing']['billing_first_name']); | |
unset($fields['billing']['billing_last_name']); | |
unset($fields['billing']['billing_company']); | |
unset($fields['billing']['billing_address_1']); | |
unset($fields['billing']['billing_address_2']); | |
unset($fields['billing']['billing_city']); | |
unset($fields['billing']['billing_postcode']); | |
unset($fields['billing']['billing_country']); | |
unset($fields['billing']['billing_state']); | |
unset($fields['billing']['billing_phone']); | |
//unset($fields['order']['order_comments']); | |
unset($fields['billing']['billing_address_2']); | |
unset($fields['billing']['billing_postcode']); | |
unset($fields['billing']['billing_company']); | |
unset($fields['billing']['billing_last_name']); | |
unset($fields['billing']['billing_email']); | |
unset($fields['billing']['billing_city']); | |
return $fields; | |
} | |
add_filter( ‘woocommerce_checkout_fields’ , ‘custom_override_checkout_fields’ ); | |
// Our hooked in function – $fields is passed via the filter! | |
function custom_override_checkout_fields( $fields ) { | |
unset($fields[‘order’][‘order_comments’]); | |
unset($fields[‘billing’][‘billing_company’]); | |
unset($fields[‘billing’][‘billing_address_1′]); | |
unset($fields[‘billing’][‘billing_address_2′]); | |
unset($fields[‘billing’][‘billing_city’]); | |
unset($fields[‘billing’][‘billing_postcode’]); | |
unset($fields[‘billing’][‘billing_country’]); | |
unset($fields[‘billing’][‘billing_state’]); | |
unset($fields[‘billing’][‘billing_phone’]); | |
return $fields; | |
} | |
/* Remove Billing & Shipping Address In Woocommerce Checkout */ | |
add_action('woocommerce_checkout_init','disable_billing_shipping'); | |
function disable_billing_shipping($checkout){ | |
$checkout->checkout_fields['billing']=array(); | |
$checkout->checkout_fields['shipping']=array(); | |
return $checkout; | |
} | |
/* WOOCOMMERCE NOTES CHANGE */ | |
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' ); | |
// Our hooked in function - $fields is passed via the filter! | |
function custom_override_checkout_fields( $fields ) { | |
$fields['order']['order_comments']['placeholder'] = 'Notes about your order go here. All grains are shipped milled unless otherwise specified for whole here, also grains are packaged together unless otherwise requested. '; | |
return $fields; | |
} | |
//=========================https://gist.github.com/roykho================================= | |
//WooCommerce: How to remove star review rating under the product title when enable review is off. | |
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_rating', 10 ); | |
add_action( 'woocommerce_single_product_summary', 'my_woocommerce_template_single_rating', 10 ); | |
function my_woocommerce_template_single_rating() { | |
global $product; | |
if ( $product->post->comment_status === 'open' ) | |
wc_get_template( 'single-product/rating.php' ); | |
return true; | |
} | |
//WooCommerce: Change add to cart text and link to redirect to single product page | |
add_filter( 'woocommerce_loop_add_to_cart_link', 'change_add_to_cart_loop' ); | |
function change_add_to_cart_loop( $product ) { | |
global $product; // this may not be necessary as it should have pulled the object in already | |
return '<a href="' . esc_url( $product->get_permalink( $product->id ) ) . '">LEARN MORE</a>'; | |
} | |
//WooCommerce: Remove Dimension/Weight from product detail page | |
add_filter( 'wc_product_enable_dimensions_display', '__return_false' ); | |
//WooCommerce: Link external products to detail product page from product category list | |
add_filter( 'woocommerce_loop_add_to_cart_link', 'product_cat_external', 10, 2 ); | |
function product_cat_external( $html, $product ) { | |
if ( $product->product_type === 'external' ) { | |
return '<a href="' . get_post_permalink( $product->id ) . '" rel="nofollow" data-product_id="' . esc_attr( $product->id ) . '" data-product_sku="' . esc_attr( $product->get_sku() ) . '" class="button add_to_cart_button product_type_variable">View Detail</a>'; | |
} else { | |
return $html; | |
} | |
} | |
//WooCommerce: How to reverse product review comments order | |
add_filter( 'woocommerce_product_review_list_args', 'wc_reverse_product_reviews' ); | |
function wc_reverse_product_reviews( $args ) { | |
$args['reverse_top_level'] = true; | |
return $args; | |
} | |
//WooCommerce: How to remove shipping label in cart and checkout | |
add_filter( 'woocommerce_cart_shipping_method_full_label', 'remove_shipping_label', 10, 2 ); | |
function remove_shipping_label( $label, $method ) { | |
$new_label = preg_replace( '/^.+:/', '', $label ); | |
return $new_label; | |
} | |
//WooCommerce: Remove related products when up-sell products are defined | |
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_upsell_display', 15 ); | |
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 ); | |
add_action( 'woocommerce_after_single_product_summary', 'related_upsell_products', 15 ); | |
function related_upsell_products() { | |
global $product; | |
if ( isset( $product ) && is_product() ) { | |
$upsells = $product->get_upsells(); | |
if ( sizeof( $upsells ) > 0 ) { | |
woocommerce_upsell_display(); | |
} else { | |
woocommerce_upsell_display(); | |
woocommerce_output_related_products(); | |
} | |
} | |
} | |
//WooCommerce Product Vendors 2.0 - Add columns to WooCommerce Customer and Orders CSV Export | |
add_filter( 'wc_customer_order_csv_export_order_headers', 'wc_product_vendors_csv_export_integration_add_column_headers' ); | |
add_filter( 'wc_customer_order_csv_export_order_line_item', 'wc_product_vendors_csv_export_integration_modify_line_item', 10, 5 ); | |
add_filter( 'wc_customer_order_csv_export_order_row_one_row_per_item', 'wc_product_vendors_csv_export_integration_add_row_data', 10, 4 ); | |
function wc_product_vendors_csv_export_integration_add_column_headers( $headers ) { | |
$headers['vendor'] = 'Vendor'; | |
return $headers; | |
} | |
function wc_product_vendors_csv_export_integration_modify_line_item( $line_item, $item, $product, $order, $csv_generator ) { | |
// bail out as we only need this data if it's one row per item | |
if ( ! wc_product_vendors_csv_export_integration_is_one_row_per_item( $csv_generator ) ) { | |
return $order_data; | |
} | |
if ( $product instanceof WC_Product && 'product' === get_post_type( $product->id ) ) { | |
// add product id to line_item | |
$line_item['product_vendors_product_id'] = $product->id; | |
} | |
return $line_item; | |
} | |
function wc_product_vendors_csv_export_integration_add_row_data( $order_data, $item, $order, $csv_generator ) { | |
// bail out as this only works with one row per item | |
if ( ! wc_product_vendors_csv_export_integration_is_one_row_per_item( $csv_generator ) ) { | |
return $order_data; | |
} | |
if ( ! empty( $item['product_vendors_product_id'] ) ) { | |
$vendor = WC_Product_Vendors_Utils::is_vendor_product( $item['product_vendors_product_id'] ); | |
if ( ! empty( $vendor[0] ) ) { | |
$vendor_data = WC_Product_Vendors_Utils::get_vendor_data_by_id( $vendor[0]->term_id ); | |
if ( ! empty( $vendor_data ) ) { | |
$order_data['vendor'] = $vendor_data['name']; | |
} | |
} | |
} | |
return $order_data; | |
} | |
function wc_product_vendors_csv_export_integration_is_one_row_per_item( $csv_generator ) { | |
// sanity check - bail if CSV Export is not active, or if the provided paramater is not as expected | |
if ( ! function_exists( 'wc_customer_order_csv_export' ) || ! $csv_generator instanceof WC_Customer_Order_CSV_Export_Generator ) { | |
return false; | |
} | |
$one_row_per_item = false; | |
// determine if the selected format is "one row per item" | |
if ( version_compare( wc_customer_order_csv_export()->get_version(), '4.0.0', '<' ) ) { | |
$one_row_per_item = ( 'default_one_row_per_item' === $csv_generator->order_format || 'legacy_one_row_per_item' === $csv_generator->order_format ); | |
// v4.0.0 - 4.0.2 | |
} elseif ( ! isset( $csv_generator->format_definition ) ) { | |
// get the CSV Export format definition | |
$format_definition = wc_customer_order_csv_export()->get_formats_instance()->get_format( $csv_generator->export_type, $csv_generator->export_format ); | |
$one_row_per_item = isset( $format_definition['row_type'] ) && 'item' === $format_definition['row_type']; | |
// v4.0.3+ | |
} else { | |
$one_row_per_item = 'item' === $csv_generator->format_definition['row_type']; | |
} | |
return $one_row_per_item; | |
} | |
//Stripe Pre 4.1.14 Styles | |
//https://gist.github.com/roykho/4622d24528dcec0960cc5c6917946892 | |
#add_payment_method .woocommerce-PaymentMethod label { margin-left: 10px; } | |
#add_payment_method li { clear: right; } | |
#add_payment_method #wc-stripe_sepa-form { padding: 10px; } | |
form#order_review #payment_method_stripe { margin: 25px 0 25px 25px; } | |
form#order_review #payment_method_stripe_sepa { margin: 25px 0 25px 25px; } | |
form#order_review .payment_methods label { margin-left: 10px; } | |
form#order_review li { clear: right; } | |
form#order_review #wc-stripe_sepa-form { padding: 10px; } | |
.wc_payment_method .payment_box label { display: inline; } | |
.woocommerce-checkout #payment .payment_method_stripe, | |
#add_payment_method #payment .payment_method_stripe { position: relative; } | |
.woocommerce-checkout #payment .payment_method_stripe_bancontact, | |
#add_payment_method #payment .payment_method_stripe_bancontact { position: relative; } | |
.woocommerce-checkout #payment .payment_method_stripe_alipay, | |
#add_payment_method #payment .payment_method_stripe_alipay { position: relative; } | |
.woocommerce-checkout #payment .payment_method_stripe_eps, | |
#add_payment_method #payment .payment_method_stripe_eps { position: relative; } | |
.woocommerce-checkout #payment .payment_method_stripe_giropay, | |
#add_payment_method #payment .payment_method_stripe_giropay { position: relative; } | |
.woocommerce-checkout #payment .payment_method_stripe_ideal, | |
#add_payment_method #payment .payment_method_stripe_ideal { position: relative; } | |
.woocommerce-checkout #payment .payment_method_stripe_multibanco, | |
#add_payment_method #payment .payment_method_stripe_multibanco { position: relative; } | |
.woocommerce-checkout #payment .payment_method_stripe_p24, | |
#add_payment_method #payment .payment_method_stripe_p24 { position: relative; } | |
.woocommerce-checkout #payment .payment_method_stripe_sepa, | |
#add_payment_method #payment .payment_method_stripe_sepa { position: relative; } | |
.woocommerce-checkout #payment .payment_method_stripe_sofort, | |
#add_payment_method #payment .payment_method_stripe_sofort { position: relative; } | |
.woocommerce-checkout #payment input#payment_method_stripe, | |
#add_payment_method #payment input#payment_method_stripe { position: absolute; top: 6px; } | |
.woocommerce-checkout #payment input#payment_method_stripe_bancontact, | |
#add_payment_method #payment input#payment_method_stripe_bancontact { position: absolute; top: 6px; } | |
.woocommerce-checkout #payment input#payment_method_stripe_alipay, | |
#add_payment_method #payment input#payment_method_stripe_alipay { position: absolute; top: 6px; } | |
.woocommerce-checkout #payment input#payment_method_stripe_eps, | |
#add_payment_method #payment input#payment_method_stripe_eps { position: absolute; top: 6px; } | |
.woocommerce-checkout #payment input#payment_method_stripe_giropay, | |
#add_payment_method #payment input#payment_method_stripe_giropay { position: absolute; top: 6px; } | |
.woocommerce-checkout #payment input#payment_method_stripe_ideal, | |
#add_payment_method #payment input#payment_method_stripe_ideal { position: absolute; top: 6px; } | |
.woocommerce-checkout #payment input#payment_method_stripe_multibanco, | |
#add_payment_method #payment input#payment_method_stripe_multibanco { position: absolute; top: 6px; } | |
.woocommerce-checkout #payment input#payment_method_stripe_p24, | |
#add_payment_method #payment input#payment_method_stripe_p24 { position: absolute; top: 6px; } | |
.woocommerce-checkout #payment input#payment_method_stripe_sepa, | |
#add_payment_method #payment input#payment_method_stripe_sepa { position: absolute; top: 6px; } | |
.woocommerce-checkout #payment input#payment_method_stripe_sofort, | |
#add_payment_method #payment input#payment_method_stripe_sofort { position: absolute; top: 6px; } | |
.woocommerce-checkout #payment .payment_method_stripe label[for=payment_method_stripe] { display: block; padding-left: 32px; } | |
#add_payment_method #payment .payment_method_stripe label[for=payment_method_stripe] { display: block; padding-left: 20px; } | |
.woocommerce-checkout #payment .payment_method_stripe_bancontact label[for=payment_method_stripe_bancontact] { display: block; padding-left: 32px; } | |
#add_payment_method #payment .payment_method_stripe_bancontact label[for=payment_method_stripe_bancontact] { display: block; padding-left: 20px; } | |
.woocommerce-checkout #payment .payment_method_stripe_alipay label[for=payment_method_stripe_alipay] { display: block; padding-left: 32px; } | |
#add_payment_method #payment .payment_method_stripe_alipay label[for=payment_method_stripe_alipay] { display: block; padding-left: 20px; } | |
.woocommerce-checkout #payment .payment_method_stripe_eps label[for=payment_method_stripe_eps] { display: block; padding-left: 32px; } | |
#add_payment_method #payment .payment_method_stripe_eps label[for=payment_method_stripe_eps] { display: block; padding-left: 20px; } | |
.woocommerce-checkout #payment .payment_method_stripe_giropay label[for=payment_method_stripe_giropay] { display: block; padding-left: 32px; } | |
#add_payment_method #payment .payment_method_stripe_giropay label[for=payment_method_stripe_giropay] { display: block; padding-left: 20px; } | |
.woocommerce-checkout #payment .payment_method_stripe_ideal label[for=payment_method_stripe_ideal] { display: block; padding-left: 32px; } | |
#add_payment_method #payment .payment_method_stripe_ideal label[for=payment_method_stripe_ideal] { display: block; padding-left: 20px; } | |
.woocommerce-checkout #payment .payment_method_stripe_multibanco label[for=payment_method_stripe_multibanco] { display: block; padding-left: 32px; } | |
#add_payment_method #payment .payment_method_stripe_multibanco label[for=payment_method_stripe_multibanco] { display: block; padding-left: 20px; } | |
.woocommerce-checkout #payment .payment_method_stripe_p24 label[for=payment_method_stripe_p24] { display: block; padding-left: 32px; } | |
#add_payment_method #payment .payment_method_stripe_p24 label[for=payment_method_stripe_p24] { display: block; padding-left: 20px; } | |
.woocommerce-checkout #payment .payment_method_stripe_sepa label[for=payment_method_stripe_sepa] { display: block; padding-left: 32px; } | |
#add_payment_method #payment .payment_method_stripe_sepa label[for=payment_method_stripe_sepa] { display: block; padding-left: 20px; } | |
.woocommerce-checkout #payment .payment_method_stripe_sofort label[for=payment_method_stripe_sofort], | |
#add_payment_method #payment .payment_method_stripe_sofort label[for=payment_method_stripe_sofort] { display: block; padding-left: 32px; } | |
.woocommerce-checkout #payment ul.payment_methods li img.stripe-icon, | |
#add_payment_method #payment ul.payment_methods li img.stripe-icon { float: right; max-width: 40px; padding-left: 3px; margin: 0; } | |
.woocommerce-checkout #payment ul.payment_methods li img.stripe-bancontact-icon, | |
#add_payment_method #payment ul.payment_methods li img.stripe-bancontact-icon { max-height: 65px; max-width: 45px; } | |
@@ -155,4 +57,4 @@ form#order_review #wc-stripe_sepa-form { padding: 10px; } | |
#add_payment_method #payment ul.payment_methods li .stripe-mastercard-brand { position: absolute; top: 50%; margin-top: -10px; right: 10px; background: no-repeat url( '../images/mastercard.svg' ); display: block; width: 30px; height: 24px; } | |
.woocommerce-checkout #payment ul.payment_methods .stripe-card-group, | |
#add_payment_method #payment ul.payment_methods .stripe-card-group { position: relative; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment