I am trying to hide the Storefront handheld footer bar on the cart, footer, and account pages. I am new to coding in Wordpress and Woocommerce and coded the following and nothing works. Below are my 3 attempts what am I doing wrong? Any assistance will be greatly appreciated.
add_action('wp_head','noshowHHFCSS');
function noshowHHFCSS() {
echo '<style>
/* Do not show hand held footer bar on cart, check out and account page*/
.page-id-5 .page-id-6 .page-id-7 .storefront-handheld-footer-bar {
display: none!important;
}
</style>';
}
if ( is_cart() || is_checkout() || is_account_page() ) {
echo '<style>
/* Do not show hand held footer bar on cart, check out and account page*/
.storefront-handheld-footer-bar {
display: none!important;
}
</style>';
}
add_action( 'init', 'jk_remove_storefront_handheld_footer_bar' );
if ( is_cart() || is_checkout() || is_account_page() ) {
function jk_remove_storefront_handheld_footer_bar() {
remove_action( 'storefront_footer', 'storefront_handheld_footer_bar', 999 );
}
}
You can try something like this:
Create in your root theme folder a new folder called CSS if you don't have one already. After that create a customFooterStyle.css file with your footer style code in it.
In the function.php place this code:
function footerBarStyle() {
wp_enqueue_style( 'custom_footer_css', get_template_directory_uri() . '/css/customFooterStyle.css' );
}
if(is_cart() || is_checkout() || is_account_page() ){
add_action('wp_enqueue_scripts', 'footerBarStyle');
}
Related
I am trying to hide all checkout-fields for WP Woocommerce on the checkout page for clients who are logged in (so their info is already stored from previous orders). I am using this code, but I get errors for missing fields on pressing the checkout/finalize button.
/*remove billing fields for logged in users*/
add_filter( 'woocommerce_checkout_fields' , 'hide_billing_detail_checkout' );
function hide_billing_detail_checkout( $fields ) {
if( is_user_logged_in() ){
unset($fields['billing']);
$fields['billing'] = array();
}
return $fields;
}
I see the unset code is probably emptying everything. I would like all fields to be just hidden visually for logged in users. Any ideas?
After some testing I managed to get it done myself. For whoever needs it:
add_action( 'wp_head', 'include_styles' );
function include_styles() {
if ( is_checkout() ) {
if( is_user_logged_in() ){
echo '
<style>
.woocommerce-billing-fields {
display: none;
}
</style>
';
}
}
}
After Allow guest checkout for specific products only in WooCommerce answer to my previous question, the following code redirect users to login page:
add_action( 'template_redirect', 'checkout_redirect_non_logged_to_login_access');
function checkout_redirect_non_logged_to_login_access() {
if( is_checkout() && !is_user_logged_in()){
wp_redirect( get_permalink( get_option('woocommerce_myaccount_page_id') ) );
exit;
}
}
But I have some products which allows guest checkout (see the linked question/answer above). So how could I fix my code for the products which allows guest checkout to disable that code redirection?
You can replace my previous answer code with the following:
// Custom conditional function that checks if checkout registration is required
function is_checkout_registration_required() {
if ( ! WC()->cart->is_empty() ) {
// Loop through cart items
foreach ( WC()->cart->get_cart() as $item ) {
// Check if there is any item in cart that has not the option "Guest checkout allowed"
if ( get_post_meta( $item['product_id'], '_allow_guest_checkout', true ) !== 'yes' ) {
return true; // Found: Force checkout user registration and exit
}
}
}
return false;
}
add_filter( 'woocommerce_checkout_registration_required', 'change_tax_class_user_role', 900 );
function change_tax_class_user_role( $registration_required ) {
return is_checkout_registration_required();
}
Then your current question code will be instead:
add_action( 'template_redirect', 'checkout_redirect_non_logged_to_login_access');
function checkout_redirect_non_logged_to_login_access() {
if( is_checkout() && !is_user_logged_in() && is_checkout_registration_required() ){
wp_redirect( get_permalink( get_option('woocommerce_myaccount_page_id') ) );
exit;
}
}
Code goes in functions.php file of your active child theme (or active theme). It should works.
How can I hide/remove shipping row from admin order page? Please help, Thanks in advance.
To hide shipping lines and details a from admin order single pages you will use the following:
add_filter( 'woocommerce_order_get_items', 'custom_order_get_items', 10, 3 );
function custom_order_get_items( $items, $order, $types ) {
if ( is_admin() && $types == array('shipping') ) {
$items = array();
}
return $items;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
Maybe have a look at this?
https://wordpress.org/plugins/hide-woocommerce-product-shipping-information/
It removes the shipping info from products so maybe also from the whole site.
Add this into your function file
<?php add_action( 'init', 'hide_shipping_details' );
function hide_shipping_details() {
global $pagenow;
if( is_admin() && $pagenow == "user-edit.php") { ?>
<style> #fieldset-shipping{ display: none !important } </style>
<?php } }
you can change css as per your requirement
Try this
add_action('admin_footer', 'my_custom_script');
function my_custom_script() {
?>
<script>
jQuery(document).ready(function(){
jQuery(".wc-order-totals .label:contains('Shipping')").parent().hide();
});
</script>
<?php
}
Is there any way to change order view color link on admin page table, based on chosen payment method, currently I have 2 payment method: paypal and cash on delivery.
IF payment method "Cash on delivery" ==> change background color link red
ELSEIF payment method "Paypal" ==> change background color link green.
Here is an example:
I know is a little bit late but maybe my anwser is helpfuly for someone else. I used Wordpress in version 4.9.8 and WooCommerce in version 3.4.4
There is no direct way to change the order view link but with a little bit JavaScript and CSS it is possible to change to change the link.
My idea:
I add an CSS class for every payment method as hidden field to the order column. Then I detect the order view link with JavaScipt and add the CSS class to that link.
Code:
Plugin PHP File:
/**
* Add payment method as hidden field
*/
function my_function_to_add_the_payment_method($column)
{
// the hidden field is only added in the order column
if($column == 'order_number' )
{
global $post, $the_order;
// order data
if ( empty( $the_order ) || $the_order->get_id() !== $post->ID ) {
$the_order = wc_get_order( $post->ID );
}
// only continue if the order is not empty
if ( empty( $the_order ) ) {
return;
}
// the WooCommerce standard payment methods are:
// bacs => Direct bank transfer
// cod => Cash on delivery
// paypal => Paypal
// cheque => Check payments
// add payment method as hidden field
// JavaScript can add the css class from the data attribute to the a.order-view link
echo '<input type="hidden" class="my-hidden-payment-method" name="my-hidden-payment-method" data-class="css-'. esc_attr( $the_order->get_payment_method() ) .'" value="'. esc_attr( $the_order->get_payment_method() ) .'" />';
}
}
/**
* hook to add the payment method to the order
*/
add_action('manage_shop_order_posts_custom_column', 'my_function_to_add_the_payment_method');
/**
* Add JavaScript and CSS
*/
function my_function_to_add_the_js_file($hook)
{
if( is_admin() AND $hook == 'edit.php' AND $_GET['post_type'] == 'shop_order' )
{
// add JavaScript file and CSS file only on the "WooCommerce order overview" page (WooCommerce -> Order)
// JS
wp_enqueue_script( 'my_payment_script', plugin_dir_url(__FILE__) ."/js/my-payment-script.js", array('jquery'), NULL, true );
// CSS
wp_enqueue_style( 'my_payment_style', plugin_dir_url(__FILE__) ."/css/my-payment-style.css", array(), '1.0', 'all' );
}
}
/**
* hook to add the javascript and CSS file
*/
add_action( 'admin_enqueue_scripts', 'my_function_to_add_the_js_file' );
Javascipt "/js/my-payment-script.js":
(function( $ ) {
'use strict';
// runs over every hidden field with the class "my-hidden-payment-method"
$('.my-hidden-payment-method').each(function(i, obj) {
var $element = $(this);
// copy the css class form hidden field to the order-view link
$element.siblings('a.order-view').addClass( $element.data('class') );
});
})( jQuery );
CSS "/css/my-payment-style.css":
.css-bacs, .css-cod, .css-paypal, .css-cheque
{
padding: 10px;
border-radius: 10px;
color: white;
}
.css-bacs {
background-color: yellow;
}
.css-cod {
background-color: red;
}
.css-paypal {
background-color: green;
}
.css-cheque {
background-color: blue;
}
Result:
I have a wordpress website, its using buddypress and bbpress. I need to hide/redirect all the buddypress and bbpress pages from people who are not logged in. So if someone lands on the members page, profile page or any forum topic it needs to redirect them to the signup page.
I tried maybe 5 plugins, all of them caused issues like 404 errors, not working or just white pages.
The url structure is like this:
www.example.com/members
www.example.com/members/luke
www.example.com/forums
www.example.com/forums/forum/general-chat
Does anyone know how I can do this without a plugin?
you have to modify from within a child theme the profile-loop.php file
your-child-theme/members/single/profile/profile-loop.php
On the first line of the file, add
<?php if ( is_user_logged_in() ) : ?>
At the end of the file, insert between the last endif and the last do_action this:
<?php else : ?>
<?php echo “<div style=’width: 600px;height:25px; padding: 4px; border: 3px solid #ff0000; text-align: center; font-style:bold; font-size: 1.3em;’> You must be logged in to view a member profile</div>”; ?>
<?php endif; ?>
Change the div inline style to whatever you need accordingly to your theme. The example fits with bp-default.
If you can not do that, then try this plugin,
plugin
Try this but make sure to change the url to what you want
add_action( 'admin_init', 'redirect_non_logged_users_to_specific_page' );
function redirect_non_logged_users_to_specific_page() {
if ( !is_user_logged_in() && is_page('add page slug or i.d here') && $_SERVER['PHP_SELF'] != '/wp-admin/admin-ajax.php' ) {
wp_redirect( 'http://www.example.dev/page/' );
exit;
}
Try this in your theme/functions.php or in bp-custom.php:
function lukedi_private_check() {
if ( ! is_admin() && ! is_user_logged_in() ) {
if ( is_front_page() || is_home() || bp_is_register_page() || bp_is_activation_page() )
return;
$redirect_url = trailingslashit( site_url() ); // change this to whatever you need
// member page
if ( bp_is_user() )
bp_core_redirect( $redirect_url );
// bbPress
if( is_bbpress() )
bp_core_redirect( $redirect_url );
// members loop
$bp_current_component = bp_current_component();
if ( false != $bp_current_component ) {
if ( 'members' == $bp_current_component )
bp_core_redirect( $redirect_url );
}
}
}
add_action( 'bp_ready', 'lukedi_private_check' );