I am trying to add Custom Order Action in WooCommerce Orders Page.
I want to add two new options in Bulk Order Actions Dropdown in WooCommerce
Mark Refunded
Mark On- Hold
Any help in this regard is highly appreciated.
There are two parts to solve with this objective.
The first part is to get a custom Order Action in the metabox of the individual Orders Page. I was trying to accomplish the same thing, but didn't find anything definitive on it, so I created a tutorial here:
http://neversettle.it/add-custom-order-action-woocommerce/
The second part is to add a custom order action in the Bulk Actions drop-down of the main Orders page. Skyverge has an excellent tutorial on that here:
http://www.skyverge.com/blog/add-custom-bulk-action/
The only specific thing you will need to take note of is to use the correct post_type. For WooCommerce orders you will need to use this in place of the first example on that tutorial:
add_action('admin_footer-edit.php', 'custom_bulk_admin_footer');
function custom_bulk_admin_footer() {
global $post_type;
if($post_type == 'shop_order') {
?>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('<option>').val('export').text('<?php _e('Export')?>').appendTo("select[name='action']");
jQuery('<option>').val('export').text('<?php _e('Export')?>').appendTo("select[name='action2']");
});
</script>
<?php
}
}
Notice the shop_order replaces the post for the condition checking which post_type to add the bulk actions to.
But fundamentally, #brasofilo is correct - for the most part WooCommerce uses standard WordPress structures, post_type mechanisms, and taxonomies. The process is the same for adding a bulk action to the Orders page as it is to the Posts page.
However, you are correct about the custom Order Actions on the individual Orders page - that is WooCommerce only and you'll need to reference the first tutorial on how to solve that part.
Related
Is there any method available to display single product woocommerce_before_single_product_summary action woocommerce shop page
Yes. There are a couple ways to do this, depending on what you're actually trying to achieve:
You can override the WooCommerce shop page template (archive-product.php) in your theme (or hopefully child theme) to do the woocommerce_before_single_product_summary action
You can add the functionality you're looking for that's currently hooked into the woocommerce_before_single_product_summary action to an action that fires on the Shop page
You can create a function that will do the woocommerce_before_single_product_summary action, and hook that into an action on the Shop page (similar to option 1, but doesn't override the Shop template - in theory, preventing more work in future if/when WooCommerce updates their templates)
How to do it
Create a folder in your theme/child theme called woocommerce and copy plugins/woocommerce/templates/content-product.php to it and figure out where you want to put the woocommerce_before_single_product_summary action. Making sure you're within the <?php ?> tags, pop this is where you want: do_action( 'woocommerce_before_single_product_summary' );
Find the specific function that does what you're looking for, and add it to an action that's already firing on the Shop page. In the functions.php file of your theme/child theme, (please use a child theme), add this within the <?php ?> tags:
add_action( 'woocommerce_before_shop_loop_item', 'specific_function_you_want' );
where 'woocommerce_before_shop_loop_item' is the first action that fires on the Shop page (you can swap out for another action in content-product.php depending on where you want to put the functionality, and 'specific_function_you_want' is the name of the function currently hooked into the woocommerce_before_single_product_summary action that you're looking to replicate.
Again, within the <?php ?> tags in your functions.php file add the following:
add_action( 'woocommerce_before_shop_loop_item', 'do_before_product_summary');
function do_before_product_summary() {
do_action('woocommerce_before_single_product_summary');
}
Pros/Cons
Easiest and fastest way to do what the question asks; however: note that by default, woocommerce_before_single_product_summary only does two things: display the product image & say if the item is on sale. Both of these are already being shown on the Shop page. Since this method just does the woocommerce_before_single_product_summary action, you'll most likely have duplicated content on the Shop page. Probably not the best way to go about this.
Gives you the most granularity. I'm making the assumption that you're probably looking to get some specific functionality that is currently hooked to the woocommerce_before_single_product_summary action, and do that on the Shop page. If that is the case, this method will allow you do that, without having to worry about any other functionality that's attached to the woocommerce_before_single_product_summary action (like duplicated product image as mentioned in method 1). However, you will need to find out where that specific functionality is coming from, which will require a bit of digging.
Doesn't require the digging required in method 2, but as with method 1, will do everything that's hooked into the woocommerce_before_single_product_summary action. The big benefit to using this over method 1 is that when/if WooCommerce updates their templates in the future (as they do from time to time), you won't need to worry about keeping your template override up to date with theirs. This isn't always a big deal, but it is something to keep in mind.
I am new to wordpress and woocommerce development and I am just wondering, how to manipulate an admin-screen in a clean, updateable way.
For example, I want to add a custom field to a product edit page (see screen):
I know, that I have to write a custom extension, but is it possible, to manipulate admin-screens of other extensions? I couldn't find any suitable tutorial? Maybe someone has a hint, where to start?
The feature of creating custom fields for products is baked right into WooCommerce, whether to implement it directly in functions.php or do the same via a plugin is left to one's sole discretion.
Remi Corson has written an excellent article detailing the same.
Here's the gist :
1.Create the fields using the woocommerce_product_options_general_product_data hook
add_action( 'woocommerce_product_options_general_product_data', 'woo_add_custom_general_fields' );
function woo_add_custom_general_fields() {
// Define your fields here.
// You can create text, textarea, select, checkbox and custom fields
}
2.When product is saved save the value entered in your custom field using woocommerce_process_product_meta hook
add_action( 'woocommerce_process_product_meta', 'woo_add_custom_general_fields_save' );
function woo_add_custom_general_fields_save( $_post_id ) {
//save field values
}
WooCommerce is a WordPress plugin that will help you to turn your website into an eCommerce store.
Yes, you can write an Extension ( or ADD-On) for this plugin, in fact there are already hundreds of Extension ( free and Paid ) have been made for it.
In order to create an Extension ( or ADD-ON ) for this plugin, you need to understand 2 things:
WooCommerce API
http://docs.woothemes.com/document/create-a-plugin/
WordPress API https://codex.wordpress.org/Writing_a_Plugin
I want to have ability to choose for each page what post should appear in a sidebar, from multiple posts type. So I understand that I need a meta box with a dropdown list of all posts, but I don't know how to build this in functions.
I only found this solution which is quite similar to what I want, but this doesn't help me to much, because I can only choose from a single post type and display only in post pages.
There is a free plugin that will solve all of your woes. It's called ACF or Advanced Custom Fields. It has the ability to add a list of posts to a field and attach that field to pages. Here's how you'd do it:
First install the plugin and navigate to the custom fields screen. Setup your field exactly like this:
Then in the options below that section you need to select these options:
That will tell ACF to put the field only on pages. After you have set that up you will get a little sidebar block like this:
You can then select each post for the page and it will return that object on the frontend. You do need to use a little code to get the frontend to spit out the posts you need. Here is the code to get a frontend option from ACF. Inside of the sidebar.php file you need to add this code:
global $post; // Get the global post object
$sidebar_posts = get_field('posts', $post->ID); // Get the field using the post ID
foreach($sidebar_posts as $sidebar_post){ // Loop through posts
echo $sidebar_post->post_title; // Echo the post title
}
This will simply loop through the posts you select and echo out the title. You can do more with this by adding some other Wordpress post functions using setup_postdata(). This will allow you to do things like the_title() and the_content().
Hope this helps!
is it possible to add 2 items to a cart at the same time? like a free product that is associated with a specifically selected product?
I currently add to the cart this way
$.get('/?post_type=product&add-to-cart=' + productId, function() {
// stuff here..
});
If its not possible do you know what hooks i might need to hook into to change it?
Thanks in advance..
There may be some theme resources that load some data with same URL including the query string, which is making WP INIT function to add product another time.
My solution is to add following code in the header.php of theme before any HTML prints out:
if(isset($_GET['add-to-cart'])){
//checkout can be replaced with any slug
header('Location: '.site_url().'/checkout/');
exit;
}
I created a very basic custom post type in my WP site to hold events. Basically, a user can input an event title, some information about the event and the date.
Currently, the only time the events are being displayed are in my sidebar where I just pull the title and date of the upcoming events.
However, I want to be able to allow the user to also click on the title of the link to lead to the event's individual page. I tried previewing my custom post type event and it kept leading me to my 404.php page. The events don't seem to load into a page at all.
I'm hoping this is a small property that I didn't set when I registered my post type. Any help?
Wordpress has incorporated custom post types into the template hierarchy and you have access to them at single-$posttype.php and archive-$posttype.php.
If you create these templates and your posts don't show up in the loop, you need to reset your permalinks/flush your rewrite rules.
As well, it would help to see how you are registering your post types, as in order for your archive-$posttype.php to be available you need to call has_archive => true in your arguments.
What i've done when i needed it:
Add this code in the same function that create your post type:
add_action("template_redirect", array(&$this, 'template_redirect'));
function template_redirect() {
global $wp;
if ($wp->query_vars["post_type"] == "events")
{
include(TEMPLATEPATH . "/events.php");
die();
}
}
Then, just create events.php with the_loop (like single.php)!
Hope it helps
[]'s