Created
September 3, 2021 18:41
-
-
Save cesjam7/6bba67a748c98ff128deacb78e02e744 to your computer and use it in GitHub Desktop.
Actualziar a marca celima o trebol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php add_filter( 'bulk_actions-edit-product', 'bulk_actions_actualizar_marca', 20, 1 ); | |
function bulk_actions_actualizar_marca( $actions ) { | |
$actions['actualizar_marca_celima'] = 'Actualziar marca a Celima'; | |
$actions['actualizar_marca_trebol'] = 'Actualziar marca a Trebol'; | |
return $actions; | |
} | |
add_filter( 'handle_bulk_actions-edit-product', 'handle_bulk_action_actualizar_marca', 10, 3 ); | |
function handle_bulk_action_actualizar_marca( $redirect_to, $action, $post_ids ) { | |
$processed_ids = array(); | |
foreach ( $post_ids as $post_id ) { | |
if ( $action == 'actualizar_marca_celima' ) { | |
update_post_meta($post_id, 'marca', 'celima'); | |
} else if ( $action == 'actualizar_marca_trebol' ) { | |
update_post_meta($post_id, 'marca', 'trebol'); | |
} | |
$processed_ids[] = $post_id; | |
} | |
return $redirect_to = add_query_arg( array( | |
'actualizar_marca' => '1', | |
'processed_count' => count( $processed_ids ), | |
'processed_ids' => implode( ',', $processed_ids ), | |
), $redirect_to ); | |
} | |
add_action( 'admin_notices', 'bulk_action_admin_notice' ); | |
function bulk_action_admin_notice() { | |
if ( !empty( $_REQUEST['actualizar_marca'] ) ) { | |
$count = intval( $_REQUEST['processed_count'] ); | |
printf( '<div id="message" class="updated fade"><p>' . | |
_n( 'Se actualizó %s producto.', | |
'Se actualizaron %s productos.', | |
$count, | |
'actualizar_marca' | |
) . '</p></div>', $count ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment