Woocommerce get order id in order page - woocommerce

I try to get the order id in my hook woocommerce_checkout_process in order page but i've no value, these are the method i tried :
add_action('woocommerce_checkout_process', 'is_cumul');
function is_cumul() {
print_r(WC()->order->id);
}
}
Thanks

woocommerce_checkout_process hook is triggered before order is placed. You should use woocommerce_thankyou hook instead of it. It will give you $order_id as a function argument.

Related

How to hide some Custom Fields from Woocommerce Admin order page

When logged in as an admin and looking at an Order in Woocommerce, there's a section with all the Custom Fields. Out of the whole list I only want it to display two of them. How do I hide the rest from this view? I don't want to delete them, but just hide from this view.
For every custom field you want hidden, add the following 4 lines of code to functions.php or using Snippets plugin:
add_filter('is_protected_meta', 'my_is_protected_meta_filter1', 10, 2);
function my_is_protected_meta_filter1($protected, $meta_key) {
return $meta_key == 'automatewoo_cart_id' ? true : $protected;
}
If you want to hide more than one, add the lines above again and change 'my_is_protected_meta_filter1' to 'my_is_protected_meta_filter2', etc
if you’re using ACF pro, there is a hook you can use to remove the field on the back end, but it’s not something that’s documented..
You could use a hook to remove specific field if is_admin() returns true.
You may need to play with this a bit to get it to work, the ACF hook is
acf/get_fields
So, for example:
add_filter('acf/get_fields', 'your_function_name', 20, 2);
function your_function_name($fields, $parent) {
// remove the fields you don't want
return $fields;
}
$fields can be a nested array of fields => sub_fields.
You need to set the priority > 10 to run after the internal ACF filter
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' );
}

Trigger action when order is placed (woocommerce)

I want to update product price as shown on this example, and even when this works fine for me I need this to happen when any new order gets completed.
How can I trigger this to every order made? Is there any kind of event in Woocommerce for a new completed order, or similar?
Thank you.
Solved. This can be done with the woocommerce_thankyou action, as seen here:
add_action( 'woocommerce_thankyou', 'my_callback');
function my_callback( $order_get_id ) {
$order = wc_get_order( $order_get_id ); // Do whatever you need with the order ID
}
}

WooCommerce, WP 4.9.7 update product attribute after order

I have a product what have attribute limited-edition-counter. When someone will buy this product I need to increment this attribute.
I tried to use add_action( 'woocommerce_order_status_completed', _my_function, 10, 1);
but it isn't called after order. It's only one trigger what I found to call after each order.
I use own plugin to extends WP.
Any hints how can I solve this problem?
Thanks in advance.
you can use woocommerce_thankyou hook so it will call everytime when someone order from the store.
add_action( 'woocommerce_thankyou', 'your_function' );
function your_function()
{
//access `limited-edition-counter` attribute here and increment it here
}

Hide orders based on order status in woocommerce

I have created one custom order status named as "Hidden".
Now in woocommmerce orders admin panel, I want to hide all orders which have order status "Hidden".
Is there any hook or filter function available to achieve this?
Thanks in advance.
Please use below hook in your child theme function.php. I hope this hook will you to achieve your goal.
add_filter( 'parse_query', 'modify_filter_owner');
function modify_filter_owner( $query )
{
global $typenow;
global $pagenow;
if($typenow == 'shop_order' )
{
////Custom filter text will come here
}
}

woocommerce add extra div after price in content-product.php

guys:
I want to add a extra div after price hook. Below is my code, but it is not working. Can anyone please tell me what I did wrong?
function init_actions() {
add_action( 'woocommerce_after_shop_loop_item_title', 'see_details_button', 10 );
}
function see_details_button() {
$button = '<div>See Details</div>';
return $button;
}
You are only returning the string you want to output. Because this is an action and not a filter I think that you should print/echo the HTML instead, i.e:
echo '<div>See Details</div>';
If that does not work. Make sure that the action actually run at the right place and that the action name is correct.

Resources