Hide and show Complete action shortcut in woocommerce - wordpress

I searched a lot but didn't find any solution that work for me.
I am developing a plugin for wordpress that will work only with woocommerce. So i want that when my order status is in pending state i want to hide complete action shortcut on orders listing page.
In the above picture i want to hide middle button when my order is in pending state. I want to do it in plugin.
Any suggestion.
Thanks in advance.

Yes this can be done using 'woocommerce_admin_order_actions' filter and adding a function to a filter.
Code to be added in you plugin:
add_filter('woocommerce_admin_order_actions','wdm_verify_product_limitation',5,2);
function wdm_verify_product_limitation( $actions, $the_order ){
if ( $the_order->has_status( array( 'pending','on-hold') ) ) {
unset($actions['complete']);
}
return $actions;
}
Here i am checking if the order is in 'pending' or 'on-hold' state then don't show the Complete button for that order.(in your case remove 'on-hold' from the code )
Have tested the same. Do let me know if this works for you

Related

WooCommerce Upsells Same Order as Admin

really hoping someone can help with this as I thought it would be far more simple!
Long story short, I have created a script that populates the upsells of WooCommerce products, all works great using the API and they are there. They show on the product page as expected but in a completely different order to how they were inputted in the admin area and I cannot seem to find a way for the order to follow admin?
function filter_woocommerce_upsells_orderby( $orderby ) {
return 'menu_order';
};
add_filter( 'woocommerce_upsells_orderby', 'filter_woocommerce_upsells_orderby', 10, 1 );
Above is the hook I have found but from the options I have found such as menu order / id / price etc, there is not simply an overide option to ignore the order and just take them as they are in admin!?
Please help!
I also encountered this problem. And i have an idea.
I checked all wordpress parameters about Order & Orderby.Link is https://developer.wordpress.org/reference/classes/wp_query/#order-orderby-parameters.
And i use the paramteters name "none",It can make your orderby not based on any sorting rules.In other words, it is sorted according to upsells. here is the code.
// ORDER BY
add_filter( 'woocommerce_upsells_orderby', 'filter_woocommerce_upsells_orderby', 10, 1 );
function filter_woocommerce_upsells_orderby( $orderby ){
return "none";
};
// ORDER
add_filter( 'woocommerce_upsells_order', 'filter_woocommerce_upsells_order', 10, 1 );
function filter_woocommerce_upsells_order(){
return 'asc'; // Default is 'desc';
};
But it is still chaotic, when adding any product to upsells, it is still random. Therefore I also used a plug-in "WooCommerce Drop/Drag For Upsells Cross-Sells", which allows you to drag your products in upsell at will.
If you have any question you can ask me.
Thanks.

possible woocommce bug keep showing "total_sales" in metabox "custom field" add/edit product page?

As shown in the edit/add product page, this item "total_sales" always show up in the default metabox "custom field".
It's not doing any harm yet but it's annoying.
However, someone might edit the total sales number by accident and would cause problems.
I am writing a child theme from storeFront.
Is this a bug in woocommerce or did I accidentally changed something somewhere that causes this?
This is by default. If you think this is a bug then you can always open a thread on https://github.com/woocommerce/woocommerce/issues
EDIT
Custom fields or post meta entries can be hidden from the by default in Wordpress available »Custom Fields«-Metabox by prefixing them with a underscore - _ - as noted here.
If you want to hide the field you can use this piece of code that i wrote for you
function filter_is_protected_meta( $protected, $meta_key, $meta_type ) {
if ( $meta_key == 'total_sales' ) {
$protected = true;
}
return $protected;
}
add_filter( 'is_protected_meta', 'filter_is_protected_meta', 10, 3 );

Hide Widget based on condition using Widget Logic Plugin

My website (http://www.chicagokaraokenight.com/wordpress) is a karaoke directory where bars can list karaoke nights for free OR upgrade to a premium or featured premium listing (paid packages) to receive a more robust profile.
As part of the benefit to upgrading to a paid package, I'd like to have some widgets disappear on the paid listings.
My theme author (Listify) recommended the plugin Widget Logic and said the following:
Use https://wordpress.org/plugins/widget-logic/ to show/hide a widget depending on certain criteria.
Using something like:
wc_paid_listings_get_user_package( $package_id )
I'm still a little unclear on exactly what I should edit the logic to say and hoping someone can help. I know how to get the package ID's (if I hover over the packages on the Product page I can see them).
The widgets I wish to hide based on a listing being a paid package are Google ads, recent listings, and featured listings.
Thanks!
UPDATE: The WC Paid Listing Plugin developer has given me this code and info after I mentioned the Free package ID is 971:
global $post;
$used_package = get_post_meta( $post->ID, '_package_id', true );
if ( 971 === $used_package ) {
// Free
}
You could wrap this in a custom function to use in widget logic:
function job_was_posted_with_package( $package_id ) {
global $post;
$used_package = get_post_meta( $post->ID, '_package_id', true );
return $package_id == $used_package;
}
Called via:
job_was_posted_with_package( 971 );
Do I have what I need now? Can someone help me identify what needs to go into functions.php, what should go in Widget Logic, etc?
Widget Logic is pretty straight forward in form of inner workings.
I assume you have a widget already created what you would need to do is make or use a function that returns a Boolean
function is_paid_member(){
// Verification Code here
return TRUE;
}
Then place is_paid_member() in the widget logic field of the affected Widget.
If you can print some code for the verification method i can most likely edit the Answer to make it workable.
Please clarify the following, is the Widget always going to be available in the Administrative interface? If yes then it would go outside of the Widget Logic scope which affect mostly activated Widgets displaying on the frontend.
Per Mike Jolley from WP Paid Listings, the correct code is:
function job_was_posted_with_package( $package_id ) {
global $post;
$used_package = get_post_meta( $post->ID, '_package_id', true );
return $package_id == $used_package;
}
which should be placed in the functions.php file.
And then:
( ! job_was_posted_with_package( ID ) && ! job_was_posted_with_package( ID ) )
or
job_was_posted_with_package( ID )
should be the condition entered into Widget Logic on the widget you want to show/hide.

how can I detect that option value has changed in wordpress?

I am working on a Wordpress plugin and I want to fire a different action based on each option value change. so how can I do that ?
Example:
$options = get_option('ACP_settings'); if $options['acp-select'] has changed from previous value than I want to fire different action based on selection
Please note that $option['acp-select'] is retrieved from select/option html form and has following values for selection:'book','air','SW','HW' and etc....
I hope I have posted my question clearly.
thanks for help
You can use wordpress hooks in the update_option() function.
In your case you can use updated_option or update_option_{$option} hooks.
The code for ACP_settings option would look like:
add_action( 'update_option_ACP_settings', function($old_value, $value, $option){
if( $old_value !== $value ){
// Your option was updated
// Run your code here
}
}, 10, 3 );

How do you remove or change the functionality of the Publish button on a custom WordPress post?

I have a custom post type and need keep the post status from getting set to 'Published' when you click the Publish button. Instead, it should work like the Save Draft button. So I either need to figure out how to just remove the Publish button so the user's can only click Save Draft our preferably, update the Publish button functionality so it doesn't set the post to publish.
You can use wordpress action hooks to modify default behaviors.
http://codex.wordpress.org/Function_Reference/add_action
In your case, you want to use the 'publish_post' hook.
So you can do
function dont_publish( $post_ID )
{
if(get_post_type($post_ID) == 'your_custom_type'){
exit;
}
}
//the dont_publish function will be called after the publish button is clicked
add_action( 'publish_post', 'dont_publish' );
The way it is above, nothing will happen at all if the publish button is clicked, but you can play around with the dont_publish function to get the results you want.
#PhoenixWing156 was close but one little change so the the other post types get updated as usual.
function dont_publish( $data , $postarr ) {
if($data['post_type'] == 'custom_post_type') {
$data['post_status'] = 'draft';
}
return $data;
}
add_filter('wp_insert_post_data' , 'dont_publish' , '99', 2);
The wp_insert_post_data hook is called before information about a post is saved to the database.
http://codex.wordpress.org/Plugin_API/Filter_Reference/wp_insert_post_data
You can try:
function dont_publish( $data , $postarr )
{
if($data['post_type'] == 'custom_post_type'){
$data['post_status'] = 'draft';
return $data;
}
}
add_filter('wp_insert_post_data' , 'dont_publish' , '99', 2);
WordPress provides the remove_meta_box() function exactly for this purpose.Just add this below code:-
add_action( 'admin_menu', function () {
remove_meta_box( 'submitdiv', 'Your_custom_post_type', 'side' );
} );
You could also disable the default saving metabox and add you own.
This is not documented well in the developer docs of wordpress.
To do this you have to hook into the "add_meta_boxes"-hook and in the hooked function yo have to call remove_meta_box('submitdiv','your-cpt','side');
The code should be something like this:
function your_cpt_metaboxes(){
remove_meta_box('submitdiv','your-cpt','side');
...
}
add_action('add_meta_boxes','function your_cpt_metaboxes');
your-cpt has to be changed to the name of your cpt of course.
I was also searching for this handy snippet and found it in the plugin Awesome Support.
The original saving metabox code can be found in /wp-admin/includes/metaboxes.php .
Just search for post_submit_meta_box (in WP 5.4 on line 22).

Resources