Skip to content

Instantly share code, notes, and snippets.

@fahdi
Last active December 29, 2015 10:49
Show Gist options
  • Save fahdi/7660044 to your computer and use it in GitHub Desktop.
Save fahdi/7660044 to your computer and use it in GitHub Desktop.
Updated code for car/totals.php
/*
WOO CUSTOM STYLESHEET
---------------------
Instructions:
Add your custom styles in this file instead of style.css so it
is easier to update the theme. Simply copy an existing style
from style.css to this file, and modify it to your liking. */
/*
GLOBAL STYLES
----------------
Add styles beneath this line that you want to be applied across your entire site */
/*
DESKTOP STYLES
-----------------
Add styles inside the media query below that you only want to be applied to the desktop layout of your site */
@media only screen and (min-width: 768px) {
/* Desktop styles go here */
}
.tip-content{
display: none; /* required */
position: absolute; /* required */
padding: 10px; border: 1px solid black;
background-color: white;
z-index:100;
}
.product-price del {
display:none;
visibility:hidden;
}
<?php
if ( ! defined( 'ABSPATH' ) ) exit;
/*-----------------------------------------------------------------------------------*/
/* Start WooThemes Functions - Please refrain from editing this section */
/*-----------------------------------------------------------------------------------*/
// WooFramework init
require_once ( get_template_directory() . '/functions/admin-init.php' );
/*-----------------------------------------------------------------------------------*/
/* Load the theme-specific files, with support for overriding via a child theme.
/*-----------------------------------------------------------------------------------*/
$includes = array(
'includes/theme-options.php', // Options panel settings and custom settings
'includes/theme-functions.php', // Custom theme functions
'includes/theme-actions.php', // Theme actions & user defined hooks
'includes/theme-comments.php', // Custom comments/pingback loop
'includes/theme-js.php', // Load JavaScript via wp_enqueue_script
'includes/sidebar-init.php', // Initialize widgetized areas
'includes/theme-widgets.php' // Theme widgets
);
// Allow child themes/plugins to add widgets to be loaded.
$includes = apply_filters( 'woo_includes', $includes );
foreach ( $includes as $i ) {
locate_template( $i, true );
}
if ( is_woocommerce_activated() ) {
locate_template( 'includes/theme-woocommerce.php', true );
}
/*-----------------------------------------------------------------------------------*/
/* You can add custom functions below */
/*-----------------------------------------------------------------------------------*/
add_action('woocommerce_single_product_summary', 'display_bulk_discount_table', 15);
add_action('woocommerce_after_shop_loop_item', 'display_bulk_discount_table', 20);
function display_bulk_discount_table() {
global $woocommerce, $post, $product;
$array_rule_sets = get_post_meta($post->ID, '_pricing_rules', true);
$_regular_price = get_post_meta($post->ID, '_regular_price', true);
if ($array_rule_sets && is_array($array_rule_sets) && sizeof($array_rule_sets) > 0){
$tempstring .= '<div class="bulk-savings-table">';
$tempstring .= '<span class="bulk-savings-table-title">Bulk Savings</span>';
$tempstring .= '<table>';
$tempstring1 .= '<tr><td class="bulk-savings-title">Quantity</td>';
$tempstring2 .='<tr><td class="bulk-savings-title">Price</td>';
foreach($array_rule_sets as $pricing_rule_sets)
{
foreach ( $pricing_rule_sets['rules'] as $key => $value ) {
if ($pricing_rule_sets['rules'][$key]['to']) {
$tempstring1 .= '<td>'.$pricing_rule_sets['rules'][$key]['from']."- ".$pricing_rule_sets['rules'][$key]['to']."</td>";
} else {
$tempstring1 .= '<td>'.$pricing_rule_sets['rules'][$key]['from']."+</td>";
}
$finalprice=$_regular_price;
$finalprice = number_format(($finalprice - ($finalprice/100)*$pricing_rule_sets['rules'][$key]['amount']), 2);
$tempstring2 .= '<td><span class="amount">'.get_woocommerce_currency_symbol().''.$finalprice."</span></td>";
}
}
$tempstring1 .= '</tr>';
$tempstring2 .= '</tr>';
$tempstring .= $tempstring1 .$tempstring2;
$tempstring .= "</table>";
$tempstring .= "</div>";
echo $tempstring;
}
}
add_filter( 'woocommerce_get_price_html', 'wpa83367_price_html', 100, 2 );
function wpa83367_price_html( $finalprice ){
global $woocommerce, $post, $product;
$array_rule_sets = get_post_meta($post->ID, '_pricing_rules', true);
$_regular_price = get_post_meta($post->ID, '_regular_price', true);
if ($array_rule_sets < 1) {
return $finalprice;
}
else {
foreach($array_rule_sets as $pricing_rule_sets)
{
foreach ( $pricing_rule_sets['rules'] as $key => $value ) {
$finalprice=$_regular_price;
$finalprice = number_format(($finalprice - ($finalprice/100)*$pricing_rule_sets['rules'][$key]['amount']), 2);
if($key == count($pricing_rule_sets['rules'])-0) {
return ''.get_woocommerce_currency_symbol().''.$finalprice.'';
}
}
}
}
}
/*-----------------------------------------------------------------------------------*/
/* Don't add any code below here or the sky will fall down */
/*-----------------------------------------------------------------------------------*/
?>
<?php
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! is_admin() ) { add_action( 'wp_enqueue_scripts', 'woothemes_add_javascript' ); }
if ( ! function_exists( 'woothemes_add_javascript' ) ) {
function woothemes_add_javascript() {
global $woo_options;
wp_register_script( 'prettyPhoto', get_template_directory_uri() . '/includes/js/jquery.prettyPhoto.js', array( 'jquery' ) );
wp_register_script( 'enable-lightbox', get_template_directory_uri() . '/includes/js/enable-lightbox.js', array( 'jquery', 'prettyPhoto' ) );
wp_register_script( 'google-maps', 'http://maps.google.com/maps/api/js?sensor=false' );
wp_register_script( 'google-maps-markers', get_template_directory_uri() . '/includes/js/markers.js' );
wp_register_script( 'flexslider', get_template_directory_uri() . '/includes/js/jquery.flexslider-min.js', array( 'jquery' ) );
wp_register_script( 'featured-slider', get_template_directory_uri() . '/includes/js/featured-slider.js', array( 'jquery' , 'flexslider' ) );
wp_register_script( 'infinite-scroll', get_template_directory_uri() . '/includes/js/jquery.infinitescroll.min.js', array( 'jquery' ) );
wp_register_script( 'masonry', get_template_directory_uri() . '/includes/js/jquery.masonry.min.js', array( 'jquery' ) );
wp_enqueue_script( 'third party', get_template_directory_uri() . '/includes/js/third-party.js', array( 'jquery' ) );
wp_enqueue_script( 'tiptip', get_template_directory_uri() . '/includes/js/jquery.tiptip.min.js', array( 'jquery' ) );
wp_enqueue_script( 'general', get_template_directory_uri() . '/includes/js/general.js', array( 'jquery' ) );
wp_enqueue_script( 'ezpz_tooltip', get_template_directory_uri() . '/includes/js/ jquery.ezpz_tooltip.min.js', array( 'jquery' ) );
// Load Google Script on Contact Form Page Template
if ( is_page_template( 'template-contact.php' ) ) {
wp_enqueue_script( 'google-maps' );
wp_enqueue_script( 'google-maps-markers' );
} // End If Statement
// Load infinite scroll on shop page / product cats
if ( is_woocommerce_activated() ) {
if ( ( $woo_options['woocommerce_archives_infinite_scroll'] == 'true' ) && ( is_shop() || is_product_category() ) ) {
wp_enqueue_script( 'infinite-scroll' );
}
}
// Load Masonry on the blog grid layout
if ( is_page_template( 'template-blog-grid.php' ) ) {
wp_enqueue_script( 'masonry' );
add_action( 'wp_head', 'woo_fire_masonry' );
}
do_action( 'woothemes_add_javascript' );
} // End woothemes_add_javascript()
}
if ( ! is_admin() ) { add_action( 'wp_print_styles', 'woothemes_add_css' ); }
if ( ! function_exists( 'woothemes_add_css' ) ) {
function woothemes_add_css () {
wp_register_style( 'prettyPhoto', get_template_directory_uri().'/includes/css/prettyPhoto.css' );
do_action( 'woothemes_add_css' );
} // End woothemes_add_css()
}
if ( ! function_exists( 'woo_fire_masonry' ) ) {
function woo_fire_masonry () { ?>
<script>
jQuery(document).ready(function($){
if (jQuery(window).width() > 767) {
jQuery('.blog-grid').masonry({
itemSelector: '.post',
// set columnWidth a fraction of the container width
columnWidth: function( containerWidth ) {
return containerWidth / 2;
}
});
}
});
</script>
<?php }
}
// Add an HTML5 Shim
add_action( 'wp_head', 'html5_shim' );
if ( ! function_exists( 'html5_shim' ) ) {
function html5_shim() {
?>
<!--[if lt IE 9]>
<script src="https://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<?php
} // End html5_shim()
}
add_action( 'woothemes_add_javascript' , 'woo_load_featured_slider_js' );
function woo_load_featured_slider_js() {
if ( is_home() ) {
//Slider settings
$settings = array(
'featured_speed' => '7',
'featured_hover' => 'true',
'featured_action' => 'true',
'featured_touchswipe' => 'true',
'featured_animation_speed' => '0.6',
'featured_pagination' => 'false',
'featured_nextprev' => 'true',
'featured_animation' => 'fade'
);
$settings = woo_get_dynamic_values( $settings );
if ( $settings['featured_speed'] == '0' ) { $slideshow = 'false'; } else { $slideshow = 'true'; }
if ( $settings['featured_touchswipe'] ) { $touchSwipe = 'true'; } else { $touchSwipe = 'false'; }
if ( $settings['featured_hover'] ) { $pauseOnHover = 'true'; } else { $pauseOnHover = 'false'; }
if ( $settings['featured_action'] ) { $pauseOnAction = 'true'; } else { $pauseOnAction = 'false'; }
if ( ! in_array( $settings['featured_animation'], array( 'fade', 'slide' ) ) ) { $settings['featured_animation'] = 'fade'; }
$slideshowSpeed = (int) $settings['featured_speed'] * 1000; // milliseconds
$animationDuration = (int) $settings['featured_animation_speed'] * 1000; // milliseconds
$nextprev = $settings['featured_nextprev'];
$manualControls = '';
if ( $settings['featured_pagination'] == 'true' ) {
$pagination = 'true';
} else {
$pagination = 'false';
}
$data = array(
'animation' => $settings['featured_animation'],
'controlsContainer' => '.controls-container',
'smoothHeight' => 'true',
'directionNav' => $nextprev,
'controlNav' => $pagination,
'manualControls' => $manualControls,
'slideshow' => $slideshow,
'pauseOnHover' => $pauseOnHover,
'slideshowSpeed' => $slideshowSpeed,
'animationDuration' => $animationDuration,
'touch' => $touchSwipe,
'pauseOnHover' => $pauseOnHover,
'pauseOnAction' => $pauseOnAction
);
wp_localize_script( 'featured-slider', 'woo_localized_data', $data);
wp_enqueue_script( 'featured-slider' );
} // End woo_load_featured_slider_js()
}
?>
<?php
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! is_admin() ) { add_action( 'wp_enqueue_scripts', 'woothemes_add_javascript' ); }
if ( ! function_exists( 'woothemes_add_javascript' ) ) {
function woothemes_add_javascript() {
global $woo_options;
wp_register_script( 'prettyPhoto', get_template_directory_uri() . '/includes/js/jquery.prettyPhoto.js', array( 'jquery' ) );
wp_register_script( 'enable-lightbox', get_template_directory_uri() . '/includes/js/enable-lightbox.js', array( 'jquery', 'prettyPhoto' ) );
wp_register_script( 'google-maps', 'http://maps.google.com/maps/api/js?sensor=false' );
wp_register_script( 'google-maps-markers', get_template_directory_uri() . '/includes/js/markers.js' );
wp_register_script( 'flexslider', get_template_directory_uri() . '/includes/js/jquery.flexslider-min.js', array( 'jquery' ) );
wp_register_script( 'featured-slider', get_template_directory_uri() . '/includes/js/featured-slider.js', array( 'jquery' , 'flexslider' ) );
wp_register_script( 'infinite-scroll', get_template_directory_uri() . '/includes/js/jquery.infinitescroll.min.js', array( 'jquery' ) );
wp_register_script( 'masonry', get_template_directory_uri() . '/includes/js/jquery.masonry.min.js', array( 'jquery' ) );
wp_enqueue_script( 'third party', get_template_directory_uri() . '/includes/js/third-party.js', array( 'jquery' ) );
wp_enqueue_script( 'tiptip', get_template_directory_uri() . '/includes/js/jquery.tiptip.min.js', array( 'jquery' ) );
wp_enqueue_script( 'general', get_template_directory_uri() . '/includes/js/general.js', array( 'jquery' ) );
wp_enqueue_script( 'ezpz_tooltip', get_template_directory_uri() . '/includes/js/ jquery.ezpz_tooltip.min.js', array( 'jquery' ) );
// Load Google Script on Contact Form Page Template
if ( is_page_template( 'template-contact.php' ) ) {
wp_enqueue_script( 'google-maps' );
wp_enqueue_script( 'google-maps-markers' );
} // End If Statement
// Load infinite scroll on shop page / product cats
if ( is_woocommerce_activated() ) {
if ( ( $woo_options['woocommerce_archives_infinite_scroll'] == 'true' ) && ( is_shop() || is_product_category() ) ) {
wp_enqueue_script( 'infinite-scroll' );
}
}
// Load Masonry on the blog grid layout
if ( is_page_template( 'template-blog-grid.php' ) ) {
wp_enqueue_script( 'masonry' );
add_action( 'wp_head', 'woo_fire_masonry' );
}
do_action( 'woothemes_add_javascript' );
} // End woothemes_add_javascript()
}
if ( ! is_admin() ) { add_action( 'wp_print_styles', 'woothemes_add_css' ); }
if ( ! function_exists( 'woothemes_add_css' ) ) {
function woothemes_add_css () {
wp_register_style( 'prettyPhoto', get_template_directory_uri().'/includes/css/prettyPhoto.css' );
do_action( 'woothemes_add_css' );
} // End woothemes_add_css()
}
if ( ! function_exists( 'woo_fire_masonry' ) ) {
function woo_fire_masonry () { ?>
<script>
jQuery(document).ready(function($){
if (jQuery(window).width() > 767) {
jQuery('.blog-grid').masonry({
itemSelector: '.post',
// set columnWidth a fraction of the container width
columnWidth: function( containerWidth ) {
return containerWidth / 2;
}
});
}
});
</script>
<?php }
}
// Add an HTML5 Shim
add_action( 'wp_head', 'html5_shim' );
if ( ! function_exists( 'html5_shim' ) ) {
function html5_shim() {
?>
<!--[if lt IE 9]>
<script src="https://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<?php
} // End html5_shim()
}
add_action( 'woothemes_add_javascript' , 'woo_load_featured_slider_js' );
function woo_load_featured_slider_js() {
if ( is_home() ) {
//Slider settings
$settings = array(
'featured_speed' => '7',
'featured_hover' => 'true',
'featured_action' => 'true',
'featured_touchswipe' => 'true',
'featured_animation_speed' => '0.6',
'featured_pagination' => 'false',
'featured_nextprev' => 'true',
'featured_animation' => 'fade'
);
$settings = woo_get_dynamic_values( $settings );
if ( $settings['featured_speed'] == '0' ) { $slideshow = 'false'; } else { $slideshow = 'true'; }
if ( $settings['featured_touchswipe'] ) { $touchSwipe = 'true'; } else { $touchSwipe = 'false'; }
if ( $settings['featured_hover'] ) { $pauseOnHover = 'true'; } else { $pauseOnHover = 'false'; }
if ( $settings['featured_action'] ) { $pauseOnAction = 'true'; } else { $pauseOnAction = 'false'; }
if ( ! in_array( $settings['featured_animation'], array( 'fade', 'slide' ) ) ) { $settings['featured_animation'] = 'fade'; }
$slideshowSpeed = (int) $settings['featured_speed'] * 1000; // milliseconds
$animationDuration = (int) $settings['featured_animation_speed'] * 1000; // milliseconds
$nextprev = $settings['featured_nextprev'];
$manualControls = '';
if ( $settings['featured_pagination'] == 'true' ) {
$pagination = 'true';
} else {
$pagination = 'false';
}
$data = array(
'animation' => $settings['featured_animation'],
'controlsContainer' => '.controls-container',
'smoothHeight' => 'true',
'directionNav' => $nextprev,
'controlNav' => $pagination,
'manualControls' => $manualControls,
'slideshow' => $slideshow,
'pauseOnHover' => $pauseOnHover,
'slideshowSpeed' => $slideshowSpeed,
'animationDuration' => $animationDuration,
'touch' => $touchSwipe,
'pauseOnHover' => $pauseOnHover,
'pauseOnAction' => $pauseOnAction
);
wp_localize_script( 'featured-slider', 'woo_localized_data', $data);
wp_enqueue_script( 'featured-slider' );
} // End woo_load_featured_slider_js()
}
?>
<?php
/**
* Cart totals
*
* @author WooThemes
* @package WooCommerce/Templates
* @version 2.0.0
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
global $woocommerce, $post, $product;
$available_methods = $woocommerce->shipping->get_available_shipping_methods();
?>
<div class="cart_totals <?php if ( $woocommerce->customer->has_calculated_shipping() ) echo 'calculated_shipping'; ?>">
<h3>Order Summary</h3>
<?php do_action( 'woocommerce_before_cart_totals' ); ?>
<?php if ( ! $woocommerce->shipping->enabled || $available_methods || ! $woocommerce->customer->get_shipping_country() || ! $woocommerce->customer->has_calculated_shipping() ) : ?>
<div>
<table cellspacing="0">
<tbody>
<tr class="cart-subtotal">
<th><strong><?php _e( 'Product Total', 'woocommerce' ); ?></strong></th>
<td><strong><?php echo $woocommerce->cart->get_cart_subtotal(); ?></strong></td>
</tr>
<?php if ( $woocommerce->cart->get_discounts_before_tax() ) : ?>
<tr class="discount">
<th><?php _e( 'Cart Discount', 'woocommerce' ); ?> <a href="<?php echo add_query_arg( 'remove_discounts', '1', $woocommerce->cart->get_cart_url() ) ?>"><?php _e( '[Remove]', 'woocommerce' ); ?></a></th>
<td>-<?php echo $woocommerce->cart->get_discounts_before_tax(); ?></td>
</tr>
<?php endif; ?>
<?php if ( $woocommerce->cart->needs_shipping() && $woocommerce->cart->show_shipping() && ( $available_methods || get_option( 'woocommerce_enable_shipping_calc' ) == 'yes' ) ) : ?>
<?php do_action( 'woocommerce_cart_totals_before_shipping' ); ?>
<tr class="shipping">
<th><?php _e( 'Delivery', 'woocommerce' ); ?></th>
<td><span><?php woocommerce_get_template( 'cart/shipping-methods.php', array( 'available_methods' => $available_methods ) ); ?></span></td>
</tr>
<?php do_action( 'woocommerce_cart_totals_after_shipping' ); ?>
<?php endif ?>
<?php if ( $woocommerce->cart->get_discounts_after_tax() ) : ?>
<tr class="discount">
<th><?php _e( 'Order Discount', 'woocommerce' ); ?> <a href="<?php echo add_query_arg( 'remove_discounts', '2', $woocommerce->cart->get_cart_url() ) ?>"><?php _e( '[Remove]', 'woocommerce' ); ?></a></th>
<td>-<?php echo $woocommerce->cart->get_discounts_after_tax(); ?></td>
</tr>
<?php endif; ?>
<?php do_action( 'woocommerce_cart_totals_before_order_total' ); ?>
<tr class="total last">
<th><strong><?php _e( 'Amount payable', 'woocommerce' ); ?></strong></th>
<td>
<strong><?php echo $woocommerce->cart->get_total(); ?></strong>
</td>
</tr>
<?php do_action( 'woocommerce_cart_totals_after_order_total' ); ?>
</tbody>
</table>
</div>
<?php if ( isset( $available_methods['free_shipping'] )) : ?>
<h4>You have saved:</h4>
<table>
<tbody>
<tr class="discount">
<th>Free Delivery</th>
<td><?php $woocommerce_flat_rate_settings = get_option('woocommerce_flat_rate_settings');
echo '-' . woocommerce_price( $woocommerce_flat_rate_settings['cost_per_order'] ); ?></td>
</tr>
<tr class="discount">
<th>Bulk savings</th>
<td><?php
$array_rule_sets = get_post_meta($post->ID, '_pricing_rules', true);
$_regular_price = get_post_meta($post->ID, '_regular_price', true);
$finalprice=$_regular_price;
$finalprice = number_format(($finalprice - ($finalprice/100)*$pricing_rule_sets['rules'][$key]['amount']), 2);
$tempstring2 .= '<span class="amount">'.get_woocommerce_currency_symbol().''.$finalprice."</span></td>";
$savings_total=0;
foreach ($woocommerce->cart->cart_contents as $cart_key => $cart_item_array) {
$savings_total=$savings_total+ $cart_item_array['quantity']*($cart_item_array['discounts']['price']- $cart_item_array['discounts']['discounted']);
}
echo '<span class="amount">-'.get_woocommerce_currency_symbol().$savings_total.'</span></td>';
?>
</tr>
</tbody>
</table>
<?php
endif; ?>
<?php elseif( $woocommerce->cart->needs_shipping() ) : ?>
<?php if ( ! $woocommerce->customer->get_shipping_state() || ! $woocommerce->customer->get_shipping_postcode() ) : ?>
<div class="woocommerce-info">
<p><?php _e( 'No shipping methods were found; please recalculate your shipping and enter your state/county and zip/postcode to ensure there are no other available methods for your location.', 'woocommerce' ); ?></p>
</div>
<?php else : ?>
<?php
$customer_location = $woocommerce->countries->countries[ $woocommerce->customer->get_shipping_country() ];
echo apply_filters( 'woocommerce_cart_no_shipping_available_html',
'<div class="woocommerce-error"><p>' .
sprintf( __( 'Sorry, it seems that there are no available shipping methods for your location (%s).', 'woocommerce' ) . ' ' . __( 'If you require assistance or wish to make alternate arrangements please contact us.', 'woocommerce' ), $customer_location ) .
'</p></div>'
);
?>
<?php endif; ?>
<?php endif; ?>
<?php if ( $woocommerce->cart->coupons_enabled() ) { ?>
<div class="coupon">
<label for="coupon_code">Discount Code:</label> <input name="coupon_code" class="input-text" id="coupon_code" value="" /> <input type="submit" class="button" name="apply_coupon" value="<?php _e( 'Apply', 'woocommerce' ); ?>" />
<?php do_action('woocommerce_cart_coupon'); ?>
</div>
<?php } ?>
<?php do_action( 'woocommerce_after_cart_totals' ); ?>
<div class="checkout_button_cart_page checkout_bottom"><a class="checkout-button checkout-top button alt" href="/checkout/">Go To Secure Checkout</a>
<img src="/wp-content/themes/superstore/images/payment.gif" alt="payment">
<!--
<img src="/wp-content/themes/superstore/images/arrow-right.png" alt="arrow right">
<p>you can choose a delivery date when you checkout</p>
-->
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment