Reputation: 558
I have to add an extra column with checkbox to WordPress/WooCommerce product listing in the admin panel.
Its purpose is to quickly update extra meta parameter of the product without entering quick edit.
I added a checkbox column, but I have a problem with placing the column before the featured star column as on the attached image. How to update meta with ajax in such case?
Current code:
add_action( 'manage_product_posts_custom_column', 'print_extra_columns', 15, 3 );
add_filter( 'manage_product_posts_columns', 'add_extra_columns', 15 );
function print_extra_columns( $value, $column_name )
{
if( $value == "extra" ) {
$checkbox ='<input type="checkbox" name="extra" />';
echo $checkbox;
}
}
function add_extra_columns( $defaults )
{
$defaults['extra'] = 'Extra';
return $defaults;
}
Upvotes: 2
Views: 1702
Reputation: 883
Actually this task can be implemented in 4 steps:
manage_edit-product_columns
(You did it!)manage_posts_custom_column
(You did it!)wp_ajax_
action hook (To do!)By the way, you can find the complete code for your task in this tutorial: https://rudrastyh.com/woocommerce/columns.html#checkbox_column_with_ajax
Upvotes: 1