{"id":14486,"date":"2024-02-27T14:35:23","date_gmt":"2024-02-27T22:35:23","guid":{"rendered":"https:\/\/codedcommerce.com\/?page_id=14486"},"modified":"2024-09-11T19:42:02","modified_gmt":"2024-09-12T02:42:02","slug":"delete-customers-without-orders","status":"publish","type":"woo-code","link":"https:\/\/codedcommerce.com\/woo\/delete-customers-without-orders\/","title":{"rendered":"Delete customers without orders"},"content":{"rendered":"\n<pre class=\"wp-block-code language-php\"><code>add_action( 'admin_notices', function() {\n\n\t$args = &#91;\n\t\t'fields' => 'ID',\n\t\t'role' => 'Customer',\n\t];\n\t$customers = get_users( $args );\n\n\t$freeloaders = 0;\n\tforeach( $customers as $user_id ) {\n\t\tif( ! wc_get_customer_order_count( $user_id ) ) {\n\t\t\t$freeloaders ++;\n\t\t\twp_delete_user( $user_id );\n\t\t}\n\t\tif( $freeloaders === 1000 ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\n\twp_admin_notice(\n\t\tsprintf(\n\t\t\t'&lt;p>Found %d bad customers out of %d total customers&lt;\/p>',\n\t\t\t$freeloaders, sizeof( $customers )\n\t\t),\n\t\t&#91; 'type' => 'success' ]\n\t);\n\n} );<\/code><\/pre>\n","protected":false},"template":"","class_list":["post-14486","woo-code","type-woo-code","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/codedcommerce.com\/wp-json\/wp\/v2\/woo-code\/14486","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codedcommerce.com\/wp-json\/wp\/v2\/woo-code"}],"about":[{"href":"https:\/\/codedcommerce.com\/wp-json\/wp\/v2\/types\/woo-code"}],"wp:attachment":[{"href":"https:\/\/codedcommerce.com\/wp-json\/wp\/v2\/media?parent=14486"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}