Remove shipping row from Woocommerce admin edit order pages - php

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
}

Related

WORDPRESS astra theme Different header menu for log in and log out user

the question is just on the title, but well here's the problem i tried this code on my function.php which at first works fine, but suddenly i realized that the menus on footer changed to be the same as the header menus.
here is the code :
function wpc_wp_nav_menu_args( $args = '' ) {
if( is_user_logged_in() ) {
$args['menu'] = 'logged-out';
} else {
$args['menu'] = 'Main Menu';
}
return $args;
}
add_filter( 'wp_nav_menu_args', 'wpc_wp_nav_menu_args' );
What i want is to have a different header menus for user when they log in and log out, but the footer menus stays the same. i am currently learning how to add the conditional logic on the functions.php atm, but if there are other ways please let me know, thx in advance
Probably a bit late for a reply but I just did this in the Astra theme today, so thought I would share the know-how for others who might need it. It can easily be adjusted for any WordPress theme actually:
You can check the location of the menu and only change the menu in the location(s) you decide (in this example 'primary' and 'mobile_menu' which is what Astra theme calls the the main nav locations for desktop and mobile) :
function custom_wp_nav_menu_args( $args = '' ) {
if( $args['theme_location'] == 'primary' || $args['theme_location'] == 'mobile_menu' ) {
if( ! is_user_logged_in() ) {
$args['menu'] = 'logged-out';
}
}
return $args;
}
add_filter( 'wp_nav_menu_args', 'custom_wp_nav_menu_args' );
If you dont want to use the explicit position of the menu (in my case the nav was in a widget in the footer and not a set theme location), you can also do the same thing by using the id, name or slug of the menu. For example if you want to change the menu 'test-menu' for 'test-menu-logged-out' if the user is logged out, you can use this:
function custom_2_wp_nav_menu_args ( $args = '' ) {
$menu_slug = $args['menu']->slug;
if ( ! is_user_logged_in() && $menu_slug == 'test-menu' ){
$args['menu'] = 'test-menu-logged-out';
}
return $args;
}
add_filter( 'wp_nav_menu_args', 'custom_2_wp_nav_menu_args' );

Hide billing fields Woocommerce for existing clients

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>
';
}
}
}

Hide a specific action button conditionally in Woocommerce admin Orders list

I Would like to add some CSS to the order admin page to hide a custom order action button, but only if the order contains only downloadable products.
This is the function I need to load conditionally:
add_action( 'admin_head', 'hide_custom_order_status_dispatch_icon' );
function hide_custom_order_status_dispatch_icon() {
echo '<style>.widefat .column-order_actions a.dispatch { display: none; }</style>';
}
Is that possible?
With CSS it's not be possible.
Instead you can hook in woocommerce_admin_order_actions filter hook, where you will be able to check if all order item are downloadable and then remove the action button "dispatch":
add_filter( 'woocommerce_admin_order_actions', 'custom_admin_order_actions', 900, 2 );
function custom_admin_order_actions( $actions, $the_order ){
// If button action "dispatch" doesn't exist we exit
if( ! $actions['dispatch'] ) return $actions;
// Loop through order items
foreach( $the_order->get_items() as $item ){
$product = $item->get_product();
// Check if any product is not downloadable
if( ! $product->is_downloadable() )
return $actions; // Product "not downloadable" Found ==> WE EXIT
}
// If there is only downloadable products, We remove "dispatch" action button
unset($actions['dispatch']);
return $actions;
}
Code goes in function.php file of the active child theme (or active theme).
This is untested but should work…
You will have to check that 'dispatch' is the correct slug for this action button…

Add a CSS class to an item when Woocommerce cart is empty

I am trying to hide my cart when it is empty, so I decided to add a CSS class to the cart HTML item when the cart is empty, here is my current code:
function x_woocommerce_navbar_menu_item( $items, $args ) {
if (WC()->cart->cart_contents_count == 0 ) {
echo '<script type="text/javascript">
$(document).ready(function() {
$("#header_cart").addClass("zero");
});
</script>';
}
I am adding this to my functionts.php file
Am I missing anything?
It will be good if you add the class to body to make the hierarchy in CSS. Use the following code in functions.php :
function tristup_body_classes( $classes )
{
global $woocommerce;
if( is_cart() && WC()->cart->cart_contents_count == 0){
$classes[]='empty-cart';
}
return $classes;
}
add_filter( 'body_class', 'tristup_body_classes' );
This code will add a class "empty-cart" to body.
Hope this will solve your problem.
I am posting here a solution which bases on Tristup answer, as his answer is not 100% correct which observed Yahya Hussein.
add_filter( 'body_class','shoppingCartNotEmpty' );
function shoppingCartNotEmpty( $classes ) {
$classes[] = WC()->cart->get_cart_contents_count() ? 'shopping-cart-not-empty'
: 'shopping-cart-empty';
return $classes;
}
When the shopping cart is empty then the CSS class shopping-cart-empty is created, otherwise shopping-cart-not-empty is available.
Please put this code in functions.php file.
function cart_empty_add_class() {
global $woocommerce;
if ( empty($woocommerce->cart->cart_contents) ) {
echo '<script type="text/javascript">
$(document).ready(function() {
$("#header_cart").addClass("zero");
});
</script>';
exit;
}
}
add_action( 'wp_head', 'cart_empty_add_class' );

WordPress: how to hide toolbar in post editor?

I have a Custom Post Type (Products) in my WordPress web site.
This is a WooCommerce Product, if it's necessary to know.
I need to hide toolbar (1) into wp-editor on Add Product page.
Also I need to hide "Add media" button (2) and "Visual/Text" tabs (3).
How do I hide them?
Maybe it make sense to change this WordPress Editor to the textarea with the same value of "name" attribute with using of some hooks?
You can use function.php or plugin to manage this code.You need to put a action.
Remove media button:
function z_remove_media_controls() {
remove_action( 'media_buttons', 'media_buttons' );
}
add_action('admin_head','z_remove_media_controls');
Remove Visual tab
add_filter( 'admin_footer', 'custom_edit_page_js', 99);
function custom_edit_page_js(){
echo ' <style type="text/css">
a#content-tmce, a#content-tmce:hover, #qt_content_fullscreen{
display:none;
}
</style>';
echo ' <script type="text/javascript">
jQuery(document).ready(function(){
jQuery("#content-tmce").attr("onclick", null);
});
</script>';
}
You can Identify post type is,
if( get_post_type() == 'product' && is_admin()) {
//do some stuff
}
I found here this elegant solution:
function wpse_199918_wp_editor_settings( $settings, $editor_id ) {
if ( $editor_id === 'content' && get_current_screen()->post_type === 'custom_post_type' ) {
$settings['tinymce'] = false;
$settings['quicktags'] = false;
$settings['media_buttons'] = false;
}
return $settings;
}
add_filter( 'wp_editor_settings', 'wpse_199918_wp_editor_settings', 10, 2 );
I have found this solution:
function hide_toolbar_TinyMCE( $in ) {
$in['toolbar1'] = '';
$in['toolbar2'] = '';
$in['toolbar'] = false;
return $in;
}
add_filter( 'tiny_mce_before_init', 'hide_toolbar_TinyMCE' );
But it hide toolbar everywhere, because this is "filter" but not "action".
How do I hide it only on Product (Custom Post Type) Add/Edit page?

Categories