Remove "Custom fields" metabox in Woocommerce order edit pages - php

I'm trying to remove the 'postcustom' meta box from the order details for a simple wooCommerce shop. The div #postcustom appears in Orders--->Click on single order --> bottom of page as 'Custom Fields'. I want to get rid of it. There are loads of examples of how to do this by calling the following function:
function remove_custom_field_meta_box()
{
remove_meta_box('postcustom', 'page', 'normal');
}
I've hooked it (currently) into:
//Remove postcustom meta box
add_action('admin_menu', 'remove_custom_field_meta_box');
I've also tried 'dashboard' and 'post' as $context to no avail.
I've also tried hooking to remove_meta_boxes, admin_init, and a few others.
I'm working in a child themes functions.php and using the default wooCommerce theme. Any thoughts on why this isn't firing? That pesky #postcustom div is still there in the admin menu! Is my context incorrect? I also tried 'orders'. Thanks#

Updated: For orders in Woocommerce the post type is 'shop_order', so your code should be:
add_action( 'add_meta_boxes', 'remove_shop_order_meta_boxe', 90 );
function remove_shop_order_meta_boxe() {
remove_meta_box( 'postcustom', 'shop_order', 'normal' );
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
Or you can hide it hitting the "screen options" tab and unchecking "Custom Fields" checkbox:

Related

How To Use do_shortcode with WooCommerce One Page Checkout

I'm trying to use the WordPress do_shortcode function for the WooCommerce One Page Checkout Plugin which uses shortcode like this: [woocommerce_one_page_checkout template="product-table" product_ids="product, ids, here"]. It seems like I can only use this shortcode IF it's in the content editor and won't allow me to add this to a page template using the do_shortcode function.
Their documentation here says:
If you wish to display the One Page Checkout Shortcode using WordPress’ do_shortcode() function instead of including the shortcode in a post or page’s content, you will also need to attach custom code to the 'is_wcopc_checkout' filter and make sure a boolean true value is returned.
So I tried adding the following to the functions.php file:
add_filter( 'is_wcopc_checkout', function(){ return true; } );
and it didn't seem to do the trick.
I also tried:
add_filter( 'is_wcopc_checkout', 'my_one_page_checkout' );
function my_one_page_checkout(){
return true;
}
add_filter( 'is_wcopc_checkout', 'true' );
That didn't seem to do it either.
Am I adding this code to the functions.php wrong? Any help on how I can get the One Page Checkout Plugin to work using do_shortcode?
Here's my full code in the page template for reference:
<?php
echo do_shortcode('[woocommerce_one_page_checkout template="product-table" product_ids="62, 122, 438, 52, 433, 435, 512, 514"]');
?>
Thanks for your help.
(I tried contacting WooCommerce support and they were no help saying that this is custom code and they can't do anything to help.)
The simplest way to return a true to a filter is like sitting the call back to WP default __return_true. So the function will be like
add_filter( 'is_wcopc_checkout', '__return_true' );
There is no filter named is_wcopc_checkout in the code of WooCommerce one page checkout version 1.0.2
From their doc- You can also manually add a shortcode [woocommerce_one_page_checkout] to any page or post and use the shortcode's attributes.
Usage: [woocommerce_one_page_checkout product_ids="30,45,12"]
Some context from One page checkout readme.
To register your template, attach a callback to the 'wcopc_templates' filter and add a new array of your template's details to the $templates array passed to your function.
For example, to register a custom pricing table template, the code would be similar to:
function eg_add_opc_template( $templates ) {
$templates['my-custom-pricing-table'] = array(
'label' => __( 'My Pricing Table', 'eg' ),
'description' => __( "Display a sophisticated and colourful pricing table with each product's attributes, but not weight or dimensions.", 'eg' ),
);
return $templates;
}
add_filter( 'wcopc_templates', 'eg_add_opc_template' ) );
The key used in the $templates array should be the template's file name (excluding the extension). The label element of the array is the name displayed on the One Page Checkout dialog. The description element is used for the tooltip next to the template's name.

Does it possible to remove or replace woocommerce class on checkout page?

I have created a custom theme and I have moved woocommerce folder to my current custom theme but once i came to checkout page there is a div name woocommerce is still showing as main div. I want to hide or rename this div but I don't have any idea what action or filter hooks will be use for that.
I have also attached a image that showing woocommerce class name on check out page.
ALso I have used below hook for change main woocommerce class before checkout form but that will not remove or replace that woocommerce class.
function action_woocommerce_before_checkout_form( $checkout ) {
echo '<div class="checkout_section">';
};
// add the action
add_action( 'woocommerce_before_checkout_form', 'action_woocommerce_before_checkout_form', 10, 1 );
function action_woocommerce_after_checkout_form( $checkout ) {
echo '</div>';
};
// add the action
add_action( 'woocommerce_after_checkout_form', 'action_woocommerce_after_checkout_form', 10, 1 );
Can anyone tell me which hook should i use for remove or replace that div?

Overwrite $wp_customize from wordpress plugin

I am using a simple theme in WordPress, that pulls it's customizers sections from the plugin ThemeHunk Customizer.
I want to hide certain sections in the customizer section, but when using $wp_customize, it isn't working.
This is what I am trying to hide:
$wp_customize->add_section('section_home_ordering', array(
'title' => __('Section Ordering', 'featuredlite'),
'priority' => 3,
));
This is located in the /wp-content/plugins/themehunk-customizer/featuredlite/customizer/customizer.php file.
I have added this to my functions.php file in my child theme directory:
function customize_register_init( $wp_customize ){
$wp_customize->remove_section('section_default_home');
$wp_customize->remove_section('pro_button');
$wp_customize->remove_section('Docs_button');
$wp_customize->remove_section('section_home_ordering'); - THIS IS THE SECTION I would like removed from the /plugin/ file
}
add_action( 'customize_register', 'customize_register_init', 99 );
It doesn't seem to remove though, like it would if you were removing a section from a parent theme.
Is there another method to do this, or is this not possible to remove from a plugin rather than a parent theme?
Thank you in advance.
SOLVED I use the customize_controls_enqueue_scripts hook to input custom CSS within the wordpress customizer, so I can display certain elements as hidden!
In theme your code works fine. Maybe it depends on action hooks order.
Have you tried?
add_action( 'plugins_loaded', 'customize_register_init', 99 );
You can simply go with these documentation as it shows you can disable particular section of Home Page (FrontPage). You can change order of appearance also from the Appearance > Frontpage Section > Section Ordering.
Reference Link: https://themehunk.com/docs/shopline-theme/#frontpage-section
https://themehunk.com/product/shopline-free-shopping-theme/

Add a DIV in Woocommerce Shop Page only

I'd like to add a DIV under the title of my Shop page, but ONLY my main shop page.
I added some code in " archive-product.php " but then it display the code on every shop page.
In fact i just need a DIV saying " choose a category below " on the main Shop Page.
Thnaks a lot for your help!
Vince
Instead of overriding archive-product.php template, You can use the following custom hooked function, that will add a custom <div> below the title in shop page only:
add_action( 'woocommerce_archive_description', 'additional_div_in_shop', 5 );
function additional_div_in_shop() {
// Only on "shop" archives pages
if( ! is_shop() ) return;
// Output the div
?>
<div class="shop-below-title"><?php _e( "Choose a category below", "woocommerce" ); ?></div>
<?php
}
Code goes in function.php file of your active child theme (or active theme).
Tested and works.
Related Docs: woocommerce conditional tags
You can add that div conditionally like the following and then the div will be shown only on shop page
if ( is_shop() ) {
echo '<div>Choose a category below</div>';
}
I know this is an old post but, there is a page selected as the shop page for woocommerce. U can simply switch back to classic editor and add a div in the text section of the page u selected in the woocommerce settings. That way u don't need child theme or anything.

Add hidden meta data to product Woocommerce

I've added a custom field to my product for admin only meta data, I have hidden it using CSS.
However it still shows up in emails. Is there any way I can create a custom field where the meta data only shows up in the admin orders page?
You could try to use woocommerce_email_order_meta_fields filter hook to remove this custom field from order metadata, using unset() php function this way:
add_filter( 'woocommerce_email_order_meta_fields', 'wc_email_order_meta_remove_custom_field', 10, 3 );
function wc_email_order_meta_remove_custom_field( $fields, $sent_to_admin, $order ) {
// Replace HERE 'meta_key' by your custom field meta key or slug.
unset($fields['meta_key']);
return $fields;
}
This code goes in function.php file of your active child theme (or theme) or also in any plugin file.
This should work, but not sure as you don't provide any information and code related to the way you have set this custom field.

Categories