Changing header cart text in Storefront - wordpress

I would like to edit the text in the header mini cart in Storefront theme:
'X items'
to just :
'X'
http://demo.woothemes.com/storefront/
Where can I access this? Can't find it anywhere in storefront or woocommerce files. I can see hook in header.php:
storefront_header_cart
but can't find any function for this in other files?
I would like to remove the dropdown when you hover over it too. Where can I change this?

that functionality is handled by storefront_cart_link function...
you can override the function... open functions.php... look for require get_template_directory() . '/inc/init.php';
right above it, paste this code...
if ( ! function_exists( 'storefront_cart_link' ) ) {
function storefront_cart_link() {
?>
<a class="cart-contents" href="<?php echo esc_url( WC()->cart->get_cart_url() ); ?>" title="<?php _e( 'View your shopping cart', 'storefront' ); ?>">
<?php echo wp_kses_data( WC()->cart->get_cart_subtotal() ); ?> <span class="count"><?php echo wp_kses_data( sprintf( '%d', WC()->cart->get_cart_contents_count() ) );?></span>
</a>
<?php
}
}
storefront_cart_link is loaded with this call require get_template_directory() . '/inc/init.php';. So above will load first, making it not create that function anymore with the call of require get_template_directory() . '/inc/init.php';.
This will do the trick.. but better use child theme... you can just paste directly the function above on the child theme's functions.php. functions.php on a child theme will load first than that of the parent, so making your function exist first.

Related

add a separate payment button for each payment method in WooCommerce

I want to add a separate payment button for each payment method in WooCommerce.I designed checkout page using cart flows
I tried in chrome developers tool by copying button html content and place in every div of payment methods
but that was just temporarily changes..
I then go to plugin files editor and select cart flows plugin but don't know what's to do next
You should consider modifying the template files..
Locate the WooCommerce template files:
You can find the template files in the
"wp-content/plugins/woocommerce/templates" directory.
Copy the "checkout/payment.php" file:
Make a backup of the original file and then copy the "payment.php"
file to your theme directory.
Edit the copied file:
In the copied file, look for the section that displays the payment
methods and modify it to add separate buttons for each payment method.
Example code (That's an old woocommerce version I found in my computer and edited it) :
<input type="radio" id="payment_method_<?php echo esc_attr( $gateway->id ); ?>" class="input-radio" name="payment_method" value="<?php echo esc_attr( $gateway->id ); ?>" <?php checked( $gateway->chosen, true ); ?> />
<label for="payment_method_<?php echo esc_attr( $gateway->id ); ?>">
<?php echo wp_kses_post( $gateway->get_title() ); ?> <?php echo wp_kses_post( $gateway->get_icon() ); ?>
</label>
<div class="payment_box payment_method_<?php echo esc_attr( $gateway->id ); ?>" <?php if ( ! $gateway->chosen ) : ?>style="display:none;"<?php endif; ?>>
<?php $gateway->payment_fields(); ?>
</div>
Save and upload the file:
Save the changes and upload the edited file to your theme directory.

Woocommerce how to add title attribute to anchor tag for product name on mini cart

I want to add a title attribute to the anchor tag for the product names in the Woocommerce mini cart, so that when a customer hovers over the product name, a toolbox will appear with the product name.
Is there a function to achieve this?
Copy the file found at
wp-content/plugins/woocommerce/templates/cart/mini-cart.php -> wp-content/themes/your-theme/woocommerce/cart/mini-cart.php
into your store’s child theme .
Note that if you customize the parent theme rather than the child theme, any changes will be overwritten with theme updates.
Change code in wp-content/themes/your-theme/woocommerce/cart/mini-cart.php
Before
<a href="<?php echo esc_url( $product_permalink ); ?>">
<?php echo $thumbnail . wp_kses_post( $product_name ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</a>
After
<a href="<?php echo esc_url( $product_permalink ); ?>" title="<?php echo esc_attr($product_name); ?>">
<?php echo $thumbnail . wp_kses_post( $product_name ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</a>
Fоr tooltip you can use 'jquery-ui'. Add below code to functions.php of your theme
function my_scripts_method() {
wp_enqueue_script('jquery');
wp_enqueue_script('jquery-ui-core');
}
add_action('wp_enqueue_scripts', 'my_scripts_method');
You need to add this code to your theme in js file
jQuery( function() {
jQuery( '.woocommerce-mini-cart-item a').tooltip();
} );

Edit search results template in Wordpress

I have created a page template with a nice layout using the lovely custom fields plugin so my client can easily update the content.
I created a loop on that page template that displays the relevant information nicely;
Here is the loop I made:
<?php
$args = array( 'post_type' => 'cripps_staff', 'posts_per_page' => 300 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
echo '<div class="col-md-3 spacetop">';
echo '<a href="'.get_permalink().'">';
echo get_post_meta($post->ID,'image',true);
echo '</a>';
echo '<h2 class="staffname">';
echo get_post_meta($post->ID,'staff_name',true);
echo '</h2>';
echo '<h2 class="staffrole">';
echo get_post_meta($post->ID,'staff_role',true);
echo '</h2>';
echo '<h2 class="staffnumber">';
echo get_post_meta($post->ID,'staff_telephone_number',true);
echo '</h2>';
echo '<h2 class="staffemail">';
echo get_post_meta($post->ID,'staff_email_address',true);
echo '</h2>';
echo '</div>';
endwhile;
?>
I created taxonomies so the staff members are split into categories.
I am then using a plugin called Taxonomies filter to create those dropdown options you will see. When you select an element in the dropdowns, Wordpress goes to/changes the page to a custom search results page I created. I want my search results to be displayed exactly like my loop on the People's template. Currently it just spits it out the title in a h1 tag.
Here is the code I got from the Twenty Fourteen theme:
<?php
// Start the Loop.
while ( have_posts() ) : the_post();
/*
* Include the post format-specific template for the content. If you want to
* use this in a child theme, then include a file called called content-___.php
* (where ___ is the post format) and that will be used instead.
*/
get_template_part( 'content', get_post_format() );
endwhile;
// Previous/next post navigation.
CrippsTheme_paging_nav();
else :
// If no content, include the "No posts found" template.
get_template_part( 'content', 'none' );
endif;
?>
How can I get the search results to look exactly like my Post loop?
I managed to resolve this completely with the help of Pieter Goosen, who provided me with an awesomely detailed response, see the full answer on Wordpress development forum:
https://wordpress.stackexchange.com/questions/143023/edit-wordpress-loop-taxonomies-filter

Preventing Display of Post Gallery when on Homepage

I would like to prevent the post's gallery from displaying when the post is listed on the homepage.
I'm thinking it will utilize add_filter and apply_filter when post in on homepage.
You can add a gallery to posts by clicking the add media button. You can select existing images or upload additional images that will create a gallery within the post. This embeds a shortcode in $post['content'] that looks like [gallery ids="37,38,39,40,41,42].
The issue is that by default it displays when the post is included on homepage as well as the individual post itself.
Update: This is what I am doing right now to achieve the requirement. I suspect there will be a more elegant way.
<div class="entry-content">
<!-- Begin Post Content -->
<?php if ( is_single() ) : ?>
<?php the_content( __( 'Continue reading <span class="meta-nav">→</span>', 'faceboard' ) ); ?>
<?php else : // Filter Gallery ShortCode out ?>
<?php
$content = '';
$content = get_the_content();
$content = preg_replace('/\[gallery\sids="[0-9]+(,[0-9]+)*,?"\s?(royalslider="\d")?\]/s',"",$content);
echo wpautop( $content, 1);
?>
<?php endif; // is_single() ?>
<!-- End Post Content -->
<?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'faceboard' ), 'after' => '</div>' ) ); ?>
</div><!-- .entry-content -->
You can add the following to your theme's functions.php file or to a custom plugin (better, as you can disable it without touching the theme).
The filter post_gallery is used to create your own gallery, and the $content parameter comes empty by default. If it returns empty, the original [gallery] shortcode is processed.
Here, we are using a dummy empty value, so the filter is tricked into thinking that we are passing some actual gallery content, but it's just a white space.
add_filter( 'post_gallery', 'disable_home_galleries_so_17635042', 10, 2 );
function disable_home_galleries_so_17635042( $content, $atts )
{
// http://codex.wordpress.org/Conditional_Tags
if( is_home() )
return ' ';
return $content;
}

Overriding a theme function from plugin in WordPress

Is it possible to override a function in a theme, from a plugin? I've been struggling to find an example of how I would achieve the above.
If anyone could shed any light it would be really helpful.
edit: Adding some code
So this is my function which allows the cart in woocommerce to update using ajax:
add_filter('add_to_cart_fragments', 'woocommerce_header_add_to_cartplus_fragment', '1');
function woocommerce_header_add_to_cartplus_fragment( $fragments ) {
global $woocommerce;
$basket_icon = esc_attr($instance['basket_icon']);
ob_start();
?>
<a class="cartplus-contents" href="<?php echo $woocommerce->cart->get_cart_url(); ?>" onclick="javscript: return false;" title="<?php _e('View your shopping cart', 'woothemes'); ?>"><?php echo sprintf(_n('%d item', '%d items', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);?> - <?php echo $woocommerce->cart->get_cart_total(); ?></a>
<?php
$fragments['a.cartplus-contents'] = ob_get_clean();
return $fragments;
}
However, some themes also have a similar function built in - in these themes my code stops working which seems strange as I use the above code twice in my plugin (one is a variation of the above) and they work fine together. This is the code built in to the theme:
add_filter('add_to_cart_fragments', 'woocommerce_cart_link');
function woocommerce_cart_link() {
global $woocommerce;
ob_start();
?>
<a href="<?php echo $woocommerce->cart->get_cart_url(); ?>" title="<?php echo sprintf(_n('%d item', '%d items', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);?> <?php _e('in your shopping cart', 'woothemes'); ?>" class="cart-button ">
<span class="label"><?php _e('My Basket:', 'woothemes'); ?></span>
<?php echo $woocommerce->cart->get_cart_total(); ?>
<span class="items"><?php echo sprintf(_n('%d item', '%d items', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count); ?></span>
</a>
<?php
$fragments['a.cart-button'] = ob_get_clean();
return $fragments;
}
Unless the function is meant to be overridden, no. This is basic PHP. You can't redefine a function. If you try you will get a fatal error.
Parts of WordPress are written to be overwritten. Look at /wp-includes/pluggable.php. Every function in there is wrapped in a if( !function_exists(...) ) conditional. Unless your theme did the same, and some do for some functions, you can't overwrite.
Look around for filters that might help you instead.
Looking at your code, you should be able to unhook that. Just make sure to hook the unhook late enough. That is not a good solution, though since you are breaking theme functionality and also must know the know the names of all the hooked functions that themes are using.
Is there something in $fragments, or in $_POST or $_GET or anything else, that you can use to conditionally run your code, leaving the rest alone.

Resources