Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hamidrezayazdani/fb214982d11a2f2fc92ffda509b0b54d to your computer and use it in GitHub Desktop.
Save hamidrezayazdani/fb214982d11a2f2fc92ffda509b0b54d to your computer and use it in GitHub Desktop.
افزودن «کارهای دسته جمعی» به سفارشات ووکامرس
<?php
/**
* Add packaging option to order bulk actions
*/
function ywp_add_packaging_to_bulk_actions( $actions ) {
$actions['mark_packaging'] = 'تغییر وضعیت به بسته‌بندی';
return $actions;
}
add_filter( 'bulk_actions-edit-shop_order', 'ywp_add_packaging_to_bulk_actions', 20, 1 );
/**
* Do packaging bulk action
*/
function ywp_handle_packaging_bulk_action( $redirect_to, $action, $post_ids ) {
if ( $action !== 'mark_packaging' ) {
return $redirect_to;
}
foreach ( $post_ids as $post_id ) {
$order = wc_get_order( $post_id );
$order->update_status('packaging');
}
return $redirect_to = add_query_arg( array(
'ywp_status_packaged' => '1',
), $redirect_to );
}
add_filter( 'handle_bulk_actions-edit-shop_order', 'ywp_handle_packaging_bulk_action', 10, 3 );
/**
* Admin notice for packaging status
*/
function ywp_packaging_bulk_action_admin_notice() {
if ( empty( $_REQUEST['mark_packaging'] ) ) {
return;
}
echo '<div id="message" class="updated fade"><p>وضعیت سفارشات به بسته‌بندی تغییر کرد.</p></div>';
}
add_action( 'admin_notices', 'ywp_packaging_bulk_action_admin_notice' );
// The code goes to your active theme (or child theme) functions.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment