I want to remove header and footer from the cart page in storefront woocommerce theme with the help of custom function or hook.
Can you suggest me which function i should use to achieve this ?
Thanks.
You can do two ways. One is using CSS and another is using hooks. As you particularly asked about hooks then I will provide the code for the hooks.
You need to find out which hooks were used in header and footer of storefront theme. And then in storefront child theme, create a functions.php file (if does not exist, most probably it does exist) and then add the following code:
function remove_header_from_cart(){
if( is_cart() ){
remove_action( 'storefront_page', 'storefront_page_header', 10 );
remove_action( 'storefront_before_content', 'storefront_header_widget_region', 10 );
remove_action( 'storefront_header', 'storefront_header_container', 0);
remove_action( 'storefront_header', 'storefront_skip_links', 5 );
remove_action( 'storefront_header', 'storefront_site_branding', 20 );
remove_action( 'storefront_header', 'storefront_secondary_navigation', 30 );
remove_action( 'storefront_header', 'storefront_product_search', 40 );
remove_action( 'storefront_header', 'storefront_header_container_close', 41 );
remove_action( 'storefront_header', 'storefront_primary_navigation_wrapper', 42 );
remove_action( 'storefront_header', 'storefront_primary_navigation', 50 );
remove_action( 'storefront_header', 'storefront_header_cart', 60 );
remove_action( 'storefront_header', 'storefront_primary_navigation_wrapper_close', 68 );
}
}
add_action('wp_head','remove_header_from_cart');
function remove_footer_from_cart(){
if( is_cart() ){
remove_action( 'storefront_footer', 'storefront_footer_widgets', 10 );
remove_action( 'storefront_footer', 'storefront_credit', 20 );
}
}
add_action('wp_head','remove_footer_from_cart');
Related
I'm trying to move the variations under my thumbnails but i'm not sure where to start.. Should i use a hook or a template ?
Here's what i'm trying to do :
Feel free to give me ideas or even a solution if you ever encountered this issue !
You can use woocommerce_product_thumbnails to add your variation under the thumbnail. you need to remove default woocommerce_variable_add_to_cart action hook. try the below code. code will go in your functions.php file.
function move_variation_under_thumbnail(){
remove_action( 'woocommerce_variable_add_to_cart', 'woocommerce_variable_add_to_cart', 30 );
global $product;
// Enqueue variation scripts.
wp_enqueue_script( 'wc-add-to-cart-variation' );
// Get Available variations?
$get_variations = count( $product->get_children() ) <= apply_filters( 'woocommerce_ajax_variation_threshold', 30, $product );
// Load the template.
wc_get_template(
'single-product/add-to-cart/variable.php',
array(
'available_variations' => $get_variations ? $product->get_available_variations() : false,
'attributes' => $product->get_variation_attributes(),
'selected_attributes' => $product->get_default_attributes(),
)
);
}
add_action( 'woocommerce_product_thumbnails', 'move_variation_under_thumbnail', 10 );
Or you can do below as Martin Mirchev suggested.
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
add_action( 'woocommerce_product_thumbnails', 'woocommerce_template_single_add_to_cart', 30 );ommerce_product_thumbnails', 'woocommerce_template_single_add_to_cart', 30 );
Tested and works
I'd like to move the WooCommerce "Add to Basket" / "Add to Cart" button below the product description and extra form fields added by WP Field Factory # this page.
I've tried the following in functions.php without success:
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 50 );
and
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 25 );
Use this code in functions.php
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
add_action( 'woocommerce_after_single_product_summary', 'woocommerce_template_single_add_to_cart');
Since the description is part of the Tabs section as usual we can try to move the description tabs around the page. Try the below code in your functions page.
function move_product_tabs_override() {
remove_action( 'woocommerce_after_single_product_summary',
'woocommerce_output_product_data_tabs', 10 );
add_action( 'woocommerce_single_product_summary',
'woocommerce_output_product_data_tabs', 10 );
remove_action( 'woocommerce_single_product_summary',
'woocommerce_template_single_price', 10 );
add_action( 'woocommerce_single_product_summary',
'woocommerce_template_single_price', 10 );
}
add_action('init', 'move_product_tabs_override', 5);
You should not try changing button position directly from summary hook like this, because even if you succeed this way, your button might be placed somewhere out of the form which will break your functionality.
Rather than this, you could just modify template files from templates/single-product/add-to-cart/ folder.
I asked Studio Press support how to move the page title to a different section of the Genesis framework. They replied with code:
remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_open', 5 );
remove_action( 'genesis_entry_header', 'genesis_do_post_title' );
remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_close', 15 );
add_action( 'genesis_after_header', 'genesis_entry_header_markup_open', 11 );
add_action( 'genesis_after_header', 'genesis_do_post_title', 12 );
add_action( 'genesis_after_header', 'genesis_entry_header_markup_close', 13 );
There's a problem with this, in that it moves both Page titles and Post titles. This means on the Blog page, the Post title is moved into the position of the Page title, and the Post title has the Page title e.g. "News".
My question is: how do I move just the Page title, and not the Post title, using remove_action / add_action...?
Help appreciated.
You have 2 choices:
You can use the code in functions.php with a conditional tag like is_singular('page') See this tutorial
Or add the code to a page.php template file with a opening PHP tag like this:
remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_open', 5 );
remove_action( 'genesis_entry_header', 'genesis_do_post_title' );
remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_close', 15 );
add_action( 'genesis_after_header', 'genesis_entry_header_markup_open', 11 );
add_action( 'genesis_after_header', 'genesis_do_post_title', 12 );
add_action( 'genesis_after_header', 'genesis_entry_header_markup_close', 13 );
genesis();
I'd like to move my product's variation descriptions in Woocommerce beneath the add to cart button, and I can't find what hook I'm supposed to use. These are the variation's custom descriptions that load on selection in AJAX.
I'm able to hook another custom function beneath the add to cart button. So I think my problem is not knowing the name of the hook and/or if it's a hook versus a filter. I think it's either woocommerce_before_single_variation or woocommerce_before_add_to_cart_button.
Here's several attempts I've tried before with no luck in functions.php:
remove_action( 'woocommerce_after_single_variation','woocommerce_single_product_summary', 20 );
add_action( 'woocommerce_after_single_variation', 'woocommerce_single_product_summary', 9 );
//try #2
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20);
add_action('woocommerce_after_add_to_cart_button', 'woocommerce_single_variation', 35);
Thank you!
The functionality I was looking for is included in WooCommerce 2.4 as a default but is not done on a hook. It's added by jQuery updating a div instead - which I found in woocommerce/js/assets/frontend/add-to-cart-variation.js. So I moved the div's location instead:
add_action ('woocommerce_after_single_variation', 'move_descriptions', 50);
function move_descriptions() {
?>
<div class="woocommerce-variation-description" style="border: 1px solid transparent; height: auto;"></div>
<?php
}
I think this will do,
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20);
add_action('woocommerce_after_add_to_cart_form', 'woocommerce_template_single_excerpt');
Only move Short description if product is variable
add_action('wp_head', 'move_short_desc_for_varition');
function move_short_desc_for_varition() {
#
global $post;
$product = get_product( $post->ID );
if( $product->is_type( 'variable' ) ){
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20);
add_action('woocommerce_after_add_to_cart_form', 'woocommerce_template_single_excerpt');
}
}
The problem is in the priority of the remove hook.
I give you an example (this work for me):
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20);
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30);
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 15 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 10 );
Pay attention and try with differents priorities.
I am implementing a shop that only allows logged in users to view the add to cart buttons.
I have successfully hidden most of them with the following code:
function thread_remove_loop_button(){
if(!is_user_logged_in() ){
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
}
}
add_action('init','thread_remove_loop_button');
However, there are still some showing in the New Products & Best seller widgets. Looking at the code, I can see these are calling the shortcode
do_shortcode('[add_to_cart id="'.$product->id.'"]');
What is the best way to amend these so the add to cart button only shows for logged in users. Obviously in the template I can do something along the lines of
if(is_user_logged_in())
echo do_shortcode('[add_to_cart id="'.$product->id.'"]');
}
but it seems like there should be a better way? Along the lines of a hook or something?
add_action('init', 'bbloomer_hide_price_add_cart_not_logged_in');
function bbloomer_hide_price_add_cart_not_logged_in() {
if ( !is_user_logged_in() ) {
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
add_action( 'woocommerce_single_product_summary', 'bbloomer_print_login_to_see', 31 );
add_action( 'woocommerce_after_shop_loop_item', 'bbloomer_print_login_to_see', 11 );
}
}
function bbloomer_print_login_to_see() {
echo '' . __('Login to see prices', 'theme_name') . '';
}
put this in your plugins/woocommerce/woocommerce.php
it will hide the price and add to cart button and print a statement login to see price
The add to cart template function is pluggable, meaning that if you define a function in your theme with the same name it will override that of WooCommerce.
function woocommerce_template_loop_add_to_cart( $args = array() ) {
if(is_user_logged_in()){
wc_get_template( 'loop/add-to-cart.php' , $args );
}
}
You need to use hook which not affect other code.
add_action('init', 'hide_add_cart_not_logged_in');
function hide_add_cart_not_logged_in() {
if (!is_user_logged_in()) {
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
}
}
that only allows logged in users to view the add to cart button.
Here you can get WooCommerce Action and Filter Hook
-https://docs.woothemes.com/wc-apidocs/hook-docs.html