Show Custom Data in Woocommerce Order Details Admin Area - php

When a User Buys a Product he can generate up to 3 Serial Keys for his Product. This works fine so far. The User can see his Serials always in "my account"
The Data gets stored in the Database: Table=Usermeta Meta=Product_Serial
So from a Users Perspective evrything works fine but from the Admin Perspective not because the admin can´t see how much Serials the Customer has created and also he cant see the Serials the User is using.
Now I have created a Custom Field in the Theme functions.php with this code:
add_action( 'add_meta_boxes', 'add_meta_boxes' );
function add_meta_boxes()
{
add_meta_box(
'woocommerce-order-my-custom',
__( 'Order Custom' ),
'order_my_custom',
'shop_order',
'side',
'default'
);
}
But from here I don't know how to read out the Serial Key so the admin can see it. :( Any ideas ?

May be i am displaying data in wrong place in your order detail page. But you can check there is multipe hook avilable for this woocommerce/inculdes/admin/meta-boxes-/view/html-order-items.php.
I just take one this hook. Please add this code in functions.php
function my_function_meta_deta() {
echo "I am here";
}
add_action( 'woocommerce_admin_order_totals_after_refunded','my_function_meta_deta', $order->id );

As coder said there is multiple hooks you can also try this out.
add_action('woocommerce_admin_order_data_after_order_details', 'my_custom_order_manipulation_function');
function my_custom_order_manipulation_function( $orderID ) {
//dynamic functionalities / static html to display
}
Credits : Add order metadata to WooCommerce admin order overview

Related

WordPress Custom Fields w/ Shortcodes to use in Posts and Pages

I am new to WordPress but learning very fast. I started my first plugin that creates a custom admin menu. One of the submenus is named Business Profile. Here is what I want to do:
1). Add custom fields to the Business Profile to collection business info (ex: Business Name)
2). Each custom field needs a related shortcode
3). All shortcodes can be placed within content on Posts and Pages and replaced with the custom field value.
I'm looking for a tutorial or some direction on how to do the above without the use of a plugin. Can anyone point me in the right direction?
I believe that you want to store and retrieve only one business information.
function sample_register_my_custom_menu_page(){
add_menu_page(
__( 'Business Profile', 'business-profile' ),
'Business Profile',
'manage_options',
'business-profile-settings',
'business_profile_settings_page',
80
);
}
add_action( 'admin_menu', 'sample_register_my_custom_menu_page' );
function business_profile_settings_page(){
if ($_POST) {
// Form Submission Processing
$business_profile = array();
$business_profile['business_name'] = sanitize_text_field($_POST['business_name']);
update_option('business_profile_details', $business_profile);
}
// Form View
// Add your html form here
$business_profile = get_option( 'business_profile_details' );
// Get your saved data and pre fill your form.
}
You can further use add_shortcode to get the data from the options and display it the post.
Note: Use wp_options to store this data only if this is a single data set. If you want to save data of multiple business you may need to use a custom post for it.

Change column titles from downloads table on Woocommerce emails

I'm trying to change the "product" column title for downloadable products on customers email notification after completing a purchase.
Any advice would be greatly appreciated.
Using woocommerce_email_downloads_columns filter hook will allow you to change the column label name to something else:
// Change email downloads specific column label name
add_filter( 'woocommerce_email_downloads_columns', 'filter_wc_email_downloads_columns' );
function filter_wc_email_downloads_columns( $columns ) {
$columns['download-product'] = __( 'Name', 'woocommerce' );
return $columns;
}
Code goes in functions.php file of your active child theme (or active theme). Tested and works.
Similar: Change column titles from downloads table on Woocommerce Thankyou page

Change column name in Downloads section from email notifications in Woocommerce

I'm creating a website with downloadable products with WooCommerce. When users buy a product and receive an email, I want to customize the table of downloadable products in the email. More specific I only want to change the following:
Only thing I want to do is change 'Downloads' and 'download' to something else…
With some research, I thought I had the answer. I changed some things in order/order-details.php and order/order-downloads.php. But I think I didn't do it correctly.
Can someone tell me what I have to change exactly?
To change the title "Downloads", the right template involved is emails/email-downloads.php line 22
?><h2 class="woocommerce-order-downloads__title"><?php esc_html_e( 'Downloads', 'woocommerce' ); ?></h2>
To change the column label name "Download", you will use the following code:
add_filter('woocommerce_email_downloads_columns', 'custom_email_downloads_columns', 10, 1);
function custom_email_downloads_columns( $columns ){
$columns['download-file'] = __("New name", "woocommerce");
return $columns;
}
Code goes in function.php file of your active child theme (or active theme). Tested and work.

Woocommerce - How to show Order details (my-account) on a separate page

Right now, in woocommerce the shortcode [woocommerce_my_account] displays the entire "My Account" page with all the tabbed options.
I only want to show the order details (found under the Orders tab) on a separate page.
So, can I just use the woocommerce template orders.php (woocommerce/templates/myaccount/orders.php) and use it on a blank new page or is there a better way to go about it?
Woocommerce has function woocommerce_account_orders() which includes Orders template. You can follow the below steps to display only orders on a separate page.
Step-1: Place below code in your theme's functions.php (Place in child theme if you have created).
function woocommerce_orders() {
$user_id = get_current_user_id();
if ($user_id == 0) {
return do_shortcode('[woocommerce_my_account]');
}else{
ob_start();
wc_get_template( 'myaccount/my-orders.php', array(
'current_user' => get_user_by( 'id', $user_id),
'order_count' => $order_count
) );
return ob_get_clean();
}
}
add_shortcode('woocommerce_orders', 'woocommerce_orders');
Step-2: Place shortcode [woocommerce_orders] in any pages in admin side and check on front end.
Above Code will display orders if customer is loggedin otherwise it will display woocommerce's login/registration page.
If you want to hide "Orders" tabbed option which is on "My Account" Page then go to Admin Side and then Woocommerce > Settings > Accounts (tab) where you can see "My account endpoints", empty "orders" field there. It will hide "Orders" from frontend "My Account" page.
Edit: Make sure that you check on frontend loggedin as "Customer" user and that customer user has atleast one order placed otherwise blank page will display there.

Customizing product variations message on single product pages

I got a WooCommerce website, which hides the prices for not logged in users, and apparently it works fine, except with product variations, that even if it does what it should, is not properly done, or at least not the way I would do it.
I hides the price of the variable product, but allows you to choose options (which is fine, that way you might encourage users to register) the problem is that when you finish choosing the variables, it shows the following message "Sorry, this product is unavailable. Please choose a different combination." Which is incorrect, is not a combination problem, but a login issue. So I wouls like to ask for some help on changing this message. Just as a quick tip, There is anoter message which i have changed already in WooCommerce with a function in the child functions.php, check the code bellow, do you think I will be able to do something similar?
function my_woocommerce_membership_notice( $message ) {
if (strpos($message,'has been removed from your cart because it can no longer be purchased') !== false) {
$message = 'An item has been removed from your cart as you have been logged out for inactivity. Please login again to add products to your cart.';
}
return $message;
}
add_filter( 'woocommerce_add_error', 'my_woocommerce_membership_notice' );
You can see the actual behaviour of the website in here: http://nataliayandres.com/oxynergy/shop/my-personalized-cream/
You should try to use the WordPress gettex() function that will replace the concerned message by your custom one:
add_filter( 'gettext', 'customizing_product_variation_message', 10, 3 );
function customizing_product_variation_message( $translated_text, $untranslated_text, $domain )
{
if ($untranslated_text == 'Sorry, this product is unavailable. Please choose a different combination.') {
$translated_text = __( 'Here goes your custom text', $domain );
}
return $translated_text;
}
This code goes in function.php file of your active child theme (or theme) or also in any plugin file.

Categories