Skip to content

Instantly share code, notes, and snippets.

@felipe-pita
Last active August 12, 2020 13:03
Show Gist options
  • Save felipe-pita/751b80485f458e50af31c17da08161d3 to your computer and use it in GitHub Desktop.
Save felipe-pita/751b80485f458e50af31c17da08161d3 to your computer and use it in GitHub Desktop.
<?php
// http://www.example.com/wp-admin/admin-post.php?action=update_all_products
add_action('admin_post_update_all_products', 'update_all_products');
function update_all_products() {
$args = array(
'post_type' => 'product',
'posts_per_page' => 1, // para testar só com 1
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
global $product;
// product ID
$product_id = $product->get_id();
echo $product_id . PHP_EOL;
// sku
$product_sku = $product->get_sku();
echo $product_sku . PHP_EOL;
// Title
$product_title = $product->get_name();
echo $product_title . PHP_EOL;
update_post_meta($product_id, 'product_info_cards_block_code', $product_sku);
update_post_meta($product_id, 'product_info_cards_block_title', $product_title);
endwhile;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment