get_id()) ) {
if($mixId = getMixIdByProductId($product->get_id())) {
// Add additional class and change the label
$button = str_replace( 'add_to_cart_button', 'add_to_cart_button added product-in-cart', $button );
$button = str_replace( 'ajax_add_to_cart', '', $button );
$button = str_replace( '>Add<', '>Remove<', $button );
// Change the url to remove it from the cart instead
$doc = new DOMDocument();
$doc->loadHTML( $button );
$xpath = new DOMXPath( $doc );
$query = "//a";
$entries = $xpath->query( $query );
$href = esc_url( $entries[0]->getAttribute( 'href' ) );
$newHref = esc_url( wc_get_cart_remove_url( $mixId ) );
$button = str_replace( $href, $newHref, $button );
}
}
echo $button;
}, 1, 2);
function checkProductIsInCart($product_id) {
foreach( WC()->cart->get_cart() as $cart_item ) {
$product_in_cart = $cart_item['product_id'];
if ( $product_in_cart === $product_id ) {
return true;
}
}
return false;
}
function getMixIdByProductId($product_id) {
global $aProdSizes, $aProdTypes;
$oCurrentMix = ( isset( $_SESSION['current_mix'] ) ) ? getMixById( $_SESSION['current_mix'] ) : array();
if(!empty($oCurrentMix->mix_items)) {
foreach ( $aProdTypes as $sProdType => $sProdTypeLabel ) {
if( array_key_exists( $sProdType, $oCurrentMix->mix_items ) && !empty( $oCurrentMix->mix_items[$sProdType] ) ) {
$aMixTypeItems = $oCurrentMix->mix_items[ $sProdType ];
foreach ( $aMixTypeItems as $oMixItem ) {
if($oMixItem->product_id == $product_id) {
return $oMixItem->cart_item_key;
}
}
}
}
}
return false;
}
add_action( 'woocommerce_before_shop_loop', 'add_create_mix_steps' );
function add_create_mix_steps() {
$oCurrentMix = getCurrentMix();
$base_link = get_term_link( BASE_ID, 'product_cat' );
$nuts_link = get_term_link( NUTS, 'product_cat' );
$fruits_link = get_term_link( DRY_FRUIT, 'product_cat' );
$seeds_link = get_term_link( SEEDS_CAT, 'product_cat' );
$extra_link = get_term_link( EXTRA_CAT, 'product_cat' );
$premade_link = get_term_link( PRE_MADE_CAT, 'product_cat' );
/*if( !is_product_category('pre-made') ) {
if( empty( $oCurrentMix->mix_items['base'] ) ) {
if( is_product_category( 'base' ) ) {
echo 'Previous Step';
echo '
2
Choose your Base Ingrediant
Start with a muesli base that has no extra oil, is free from artificial flavours and is 100% NZ-grown and made by leading NZ food makers.
';
}
else {
echo 'Choose Base';
}
return '';
}
}*/
if ( is_product_category( 'base' ) ) {
echo 'Previous StepNext Step';
echo '2
SELECT A BASE
The foundation for your muesli mix. Select from the range of healthy and nutritious bases carefully designed to create the best start to your mix.
';
};
if ( is_product_category( 'nuts' ) ) {
echo 'Previous StepNext Step';
echo '3
NUTS – SELECT UP TO 3
Select three of your favourites, or add more serves of the one you love by clicking \'add\' again.
';
};
if ( is_product_category( 'fruits' ) ) {
echo 'Previous StepNext Step';
echo '4
FRUIT - SELECT UP TO 3
Select three of your favourites, or add more serves of the one you love by clicking \'add\' again.
';
};
if ( is_product_category( 'seeds' ) ) {
echo 'Previous StepNext Step';
echo '5
SEEDS AND GRAINS - SELECT UP TO 2
Select two of your favourites, or add a double serve of the one you love by clicking \'add\' again.
';
};
if ( is_product_category( 'extras' ) ) {
echo 'Previous StepView your Cart';
echo '6
NEED THAT LITTLE BIT MORE?
Sometimes you just need that little bit extra to indulge. After all, it is a serious world. Here are a couple of tasty additions that can be added to your mix as an extra treat for a small charge.
';
};
}
add_action( 'woocommerce_after_shop_loop', 'add_create_mix_steps_two' );
function add_create_mix_steps_two() {
$oCurrentMix = getCurrentMix();
$base_link = get_term_link( BASE_ID, 'product_cat' );
$nuts_link = get_term_link( NUTS, 'product_cat' );
$fruits_link = get_term_link( DRY_FRUIT, 'product_cat' );
$seeds_link = get_term_link( SEEDS_CAT, 'product_cat' );
$extra_link = get_term_link( EXTRA_CAT, 'product_cat' );
$premade_link = get_term_link( PRE_MADE_CAT, 'product_cat' );
if ( is_product_category( 'base' ) ) {
echo 'Previous StepNext Step';
}
if ( is_product_category( 'nuts' ) ) {
echo 'Previous StepNext Step';
}
if ( is_product_category( 'fruits' ) ) {
echo 'Previous StepNext Step';
}
if ( is_product_category( 'seeds' ) ) {
echo 'Previous StepNext Step';
}
if ( is_product_category( 'extras' ) ) {
echo 'Previous StepView your Cart';
}
}
add_filter( 'woocommerce_checkout_fields', 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {
$fields['billing']['billing_postcode']['label'] = 'Postcode';
$fields['shipping']['shipping_postcode']['label'] = 'Postcode';
unset( $fields['billing']['billing_country'] );
unset( $fields['shipping']['shipping_country'] );
unset( $fields['billing']['billing_company'] );
$fields['billing']['billing_state']['label'] = 'Region';
$fields['shipping']['shipping_state']['label'] = 'Region';
$fields['order']['order_comments']['placeholder'] = 'Type a short hand written message to accompany your order';
$fields['order']['order_comments']['label'] = 'Order Message';
$fields['shipping']['shipping_notes']['placeholder'] = 'Special delivery details';
return $fields;
}
// Display 24 products per page. Goes in functions.php
add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 24;' ), 20 );
add_action( 'after_setup_theme', 'remove_admin_bar' );
function remove_admin_bar() {
if ( ! current_user_can( 'administrator' ) && ! is_admin() ) {
show_admin_bar( false );
}
}
add_action( 'wp_authenticate', 'login_with_email_address' );
function login_with_email_address( $username ) {
$user = get_user_by( 'email', $username );
if ( ! empty( $user->user_login ) ) {
$username = $user->user_login;
}
return $username;
}
add_filter( 'gettext', 'change_username_wps_text' );
function change_username_wps_text( $text ) {
if ( in_array( $GLOBALS['pagenow'], [ 'wp-login.php' ] ) ) {
if ( $text == 'Username' ) {
$text = 'Username / Email';
}
}
return $text;
}
add_filter( 'add_to_cart_text', 'woo_custom_cart_button_text' ); // < 2.1
add_action( 'init', 'brad_deregister_heartbeat', 1 );
function brad_deregister_heartbeat() {
global $pagenow;
if ( 'post.php' != $pagenow && 'post-new.php' != $pagenow ) {
wp_deregister_script( 'heartbeat' );
}
}
// region remove item from cart fix
remove_action( 'woocommerce_before_cart_item_quantity_zero', 'swi_remove_item_from_mix' );
add_action( 'woocommerce_remove_cart_item', 'swi_remove_item_from_mix' ); // todo: this can go into the plugin itself: line swi.php:739
// endregion
// region my-account stuff
add_filter( 'woocommerce_account_menu_items', 'muesli_account_menu_items', 10, 1 );
/**
* Account menu items
*
* @param array $items
*
* @return array
*/
function muesli_account_menu_items( $items ) { // to move the position of the 'mixes', change the 'length' param
return array_splice( $items, 0, 2 ) + [ 'mixes' => __( 'Mixes', 'muesli' ) ] + $items;
}
add_action( 'init', 'muesli_add_my_mixes_endpoint' );
/**
* Add endpoint
*/
function muesli_add_my_mixes_endpoint() {
add_rewrite_endpoint( 'mixes', EP_PAGES );
}
add_action( 'woocommerce_account_mixes_endpoint', 'muesli_mixes_endpoint_content' );
/**
* Mixes content
*/
function muesli_mixes_endpoint_content() {
wc_get_template( 'myaccount/my-mixes.php' );
}
// endregion
// region remove some actions
add_action( 'init', 'remove_actions' );
function remove_actions() {
remove_action( 'woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10 ); // removes woocommerce's default product link (replaced with one that opens a model)
remove_action( 'woocommerce_before_shop_loop_item_title', 'product_thumbnail_with_cart', 10 ); // removes extra 'add' button that's added by parent theme
// remove_action('woocommerce_before_shop_loop_item_title', 'product_thumbnail_with_cart_alt', 10 );
remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 ); // removes woocommerce's default product title (replaced by custom one)
}
// endregion
// region muesli_template_loop_product_link_open
add_action( 'woocommerce_shop_loop_item_title', 'muesli_template_loop_product_link_open', 10 );
/**
* Insert the opening anchor tag for products in the loop.
*/
function muesli_template_loop_product_link_open() {
echo '';
}
// endregion
// region muesli_product_thumbnail_with_cart -- fixes add button being added by parent theme
add_action( 'woocommerce_before_shop_loop_item_title', 'muesli_product_thumbnail_with_cart', 10 );
function muesli_product_thumbnail_with_cart() {
echo '';
echo woocommerce_get_product_thumbnail();
echo '
';
woocommerce_template_loop_add_to_cart();
// echo '';
// echo woocommerce_get_product_thumbnail();
// echo '
';
// echo '' . do_action( 'woocommerce_shop_loop_item_title' ) . '';
// woocommerce_template_loop_add_to_cart();
}
add_action( 'woocommerce_cart_collaterals', 'woocommerce_cart_totals', 11 );
function product_thumbnail_with_cart_alt_copy() { ?>
version, "3.0", ">=" ) ) {
echo '
' . wc_get_product_category_list($product->get_id()) .'
';
} else {
echo '
' . $product->get_categories() .'
';
}
?>
' . get_the_title() . '';
}
// endregion
// region update Coupon customised text to have 'click here' link
add_filter( 'woocommerce_checkout_coupon_message', 'muesli_woocommerce_checkout_coupon_message', 100 );
function muesli_woocommerce_checkout_coupon_message( $message ) {
return $message . ' ' . __( 'Click here to enter your code', 'woocommerce' ) . '';
} // todo this can be removed in favor of changing the 'coupon text' setting in the woocommerce customizer to include the 'click here' code after 'Have a Voucher?'
// endregion
// region outputs 'Free!' when product price is 0.00
add_filter('woocommerce_get_price_html', 'change_free_price_notice', 10, 2);
function change_free_price_notice($price, $product) {
return $price === wc_price(0.00) ? 'Free!' : $price;
}
// endregion
// Remove PayPal icon and "What is Paypal?" link
add_filter( 'woocommerce_gateway_icon', 'woocommerce_remove_paypal_icon', 10, 2 );
function woocommerce_remove_paypal_icon( $icon_html, $gateway_id ) {
if( 'paypal' == $gateway_id ) {
$icon_html = '';
}
return $icon_html;
}
// Customise iconic-woo-quickview-premium layout
// add_action( 'jck_qv_summary', 'iconic_quickview_summary', 100, 3 );
// function iconic_quickview_summary( $product_id, $post, $product ) {
// if( ! empty( $_POST['variation_id'] ) ) {
// $product = wc_get_product( $_POST['variation_id'] );
// }
// if ( $product_cat_id != 65 ) {
// echo '';
// if($theSettings['popup_content_showdesc'] != 'no') include($this->plugin_path.'/inc/qv-nutrition.php');
// echo '
';
// }
// }
// Customise single add to cart button text, as used by iconic-woo-quickview-premium
add_filter( 'woocommerce_product_single_add_to_cart_text', 'woo_custom_single_add_to_cart_text' );
function woo_custom_single_add_to_cart_text() {
return __( 'Add', 'woocommerce' );
}
add_action( 'woocommerce_add_cart_item_data', 'woocommerce_clear_cart_url' );
function woocommerce_clear_cart_url() {
global $woocommerce;
$woocommerce->cart->empty_cart();
}
?>