79114139

Date: 2024-10-22 12:53:43
Score: 1.5
Natty:
Report link

As above code, I want to add limit => -1, to apply all 6000 products.

    // Change hook if needed. This will run on each refresh of the website
add_action('init','test');
function test() {
    // Get variable products.
    $args = array(
        'type' => 'variable',
        'limit' => -1, 
        'return' => 'ids',
    );
    $product_ids = wc_get_products( $args );
    foreach($product_ids as $product_id) {
        // Get the current parent sku 
        $main_sku = get_post_meta( $product_id, '_sku', true );
        // If not empty clear it
        if(!empty($main_sku)) {
            update_post_meta($product_id, '_sku', '');
        }
    }
}
Reasons:
  • RegEx Blacklisted phrase (1): I want
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: Usama