Created
March 18, 2024 09:56
-
-
Save goranefbl/4d76a5da95ebfec23bab2c8b0565f22c to your computer and use it in GitHub Desktop.
biobalkan-customers
This file contains 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_action( 'after_setup_theme', function() { | |
$current_user = wp_get_current_user(); | |
/* is guest? */ | |
if ( 0 == $current_user->ID ) { | |
return; | |
} else { | |
/* is not administrator */ | |
if ( ! in_array( 'administrator', $current_user->roles ) ) { | |
return; | |
} | |
} | |
// Function to Walk through array for umlauts | |
function encode_group_walker( &$item, $key ) { | |
$item = htmlentities( $item ); | |
} | |
// Get guest group | |
$guest_group_id = get_option( 'bm_guest_group' ); | |
// Collecting guest group settings | |
$guest_group_data = array( | |
'bm_conditional_products' => get_post_meta( $guest_group_id, 'bm_conditional_products', true ), | |
'bm_conditional_categories' => get_post_meta( $guest_group_id, 'bm_conditional_categories', true ), | |
'bm_conditional_all_products' => get_post_meta( $guest_group_id, 'bm_conditional_all_products', true ), | |
'bm_group_prices' => get_post_meta( $guest_group_id, 'bm_group_prices', true ), | |
'bm_bulk_prices' => get_post_meta( $guest_group_id, 'bm_bulk_prices', true ), | |
'bm_discount' => get_post_meta( $guest_group_id, 'bm_discount', true ), | |
'bm_discount_type' => get_post_meta( $guest_group_id, 'bm_discount_type', true ), | |
'bm_discount_name' => get_post_meta( $guest_group_id, 'bm_discount_name', true ), | |
'bm_discount_products' => get_post_meta( $guest_group_id, 'bm_discount_products', true ), | |
'bm_discount_categories' => get_post_meta( $guest_group_id, 'bm_discount_categories', true ), | |
'bm_discount_all_products' => get_post_meta( $guest_group_id, 'bm_discount_all_products', true ), | |
'bm_goods_discount' => get_post_meta( $guest_group_id, 'bm_goods_discount', true ), | |
'bm_goods_discount_type' => get_post_meta( $guest_group_id, 'bm_goods_discount_type', true ), | |
'bm_goods_discount_categories' => get_post_meta( $guest_group_id, 'bm_goods_discount_categories', true ), | |
'bm_goods_product_count' => get_post_meta( $guest_group_id, 'bm_goods_product_count', true ), | |
'bm_cart_discounts' => get_post_meta( $guest_group_id, 'bm_cart_discounts', true ), | |
'bm_tax_type' => get_post_meta( $guest_group_id, 'bm_tax_type', true ), | |
'bm_vat_type' => get_post_meta( $guest_group_id, 'bm_vat_type', true ), | |
'bm_show_sale_badge' => get_post_meta( $guest_group_id, 'bm_show_sale_badge', true ), | |
'bm_min_order_amount' => get_post_meta( $guest_group_id, 'bm_min_order_amount', true ), | |
'bm_min_order_amount_message' => get_post_meta( $guest_group_id, 'bm_min_order_amount_message', true ), | |
); | |
// Walking through array for umlauts | |
array_walk_recursive($guest_group_data, 'encode_group_walker' ); | |
// Get customer group | |
$customer_group_id = get_option( 'bm_customer_group' ); | |
// Collecting customer group settings | |
$customer_group_data = array( | |
'bm_conditional_products' => get_post_meta( $customer_group_id, 'bm_conditional_products', true ), | |
'bm_conditional_categories' => get_post_meta( $customer_group_id, 'bm_conditional_categories', true ), | |
'bm_conditional_all_products' => get_post_meta( $customer_group_id, 'bm_conditional_all_products', true ), | |
'bm_group_prices' => get_post_meta( $customer_group_id, 'bm_group_prices', true ), | |
'bm_bulk_prices' => get_post_meta( $customer_group_id, 'bm_bulk_prices', true ), | |
'bm_discount' => get_post_meta( $customer_group_id, 'bm_discount', true ), | |
'bm_discount_type' => get_post_meta( $customer_group_id, 'bm_discount_type', true ), | |
'bm_discount_name' => get_post_meta( $customer_group_id, 'bm_discount_name', true ), | |
'bm_discount_products' => get_post_meta( $customer_group_id, 'bm_discount_products', true ), | |
'bm_discount_categories' => get_post_meta( $customer_group_id, 'bm_discount_categories', true ), | |
'bm_discount_all_products' => get_post_meta( $customer_group_id, 'bm_discount_all_products', true ), | |
'bm_goods_discount' => get_post_meta( $customer_group_id, 'bm_goods_discount', true ), | |
'bm_goods_discount_type' => get_post_meta( $customer_group_id, 'bm_goods_discount_type', true ), | |
'bm_goods_discount_categories' => get_post_meta( $customer_group_id, 'bm_goods_discount_categories', true ), | |
'bm_goods_product_count' => get_post_meta( $customer_group_id, 'bm_goods_product_count', true ), | |
'bm_cart_discounts' => get_post_meta( $customer_group_id, 'bm_cart_discounts', true ), | |
'bm_tax_type' => get_post_meta( $customer_group_id, 'bm_tax_type', true ), | |
'bm_vat_type' => get_post_meta( $customer_group_id, 'bm_vat_type', true ), | |
'bm_show_sale_badge' => get_post_meta( $customer_group_id, 'bm_show_sale_badge', true ), | |
'bm_min_order_amount' => get_post_meta( $customer_group_id, 'bm_min_order_amount', true ), | |
'bm_min_order_amount_message' => get_post_meta( $customer_group_id, 'bm_min_order_amount_message', true ), | |
); | |
// Walking through array for umlauts | |
array_walk_recursive($customer_group_data, 'encode_group_walker' ); | |
// Delete old guest and customer groups | |
wp_delete_post( $guest_group_id, true ); | |
wp_delete_post( $customer_group_id, true ); | |
// Insert new guest group | |
$args = array( | |
'post_title' => 'Gast', | |
'post_name' => 'guest', | |
'post_type' => 'customer_groups', | |
'post_content' => '', | |
'post_status' => 'publish', | |
); | |
$guest_group_new_id = wp_insert_post( $args ); | |
update_option( 'bm_guest_group', $guest_group_new_id ); | |
update_post_meta( $guest_group_new_id, 'bm_all_products', 'on' ); | |
// Insert stored group settings | |
foreach ( $guest_group_data as $option_key => $option_value ) { | |
update_post_meta( $guest_group_new_id, $option_key, $option_value ); | |
} | |
// Insert new customer group | |
$args = array( | |
'post_title' => 'Kunde', | |
'post_name' => 'customer', | |
'post_type' => 'customer_groups', | |
'post_content' => '', | |
'post_status' => 'publish', | |
); | |
$customer_group_new_id = wp_insert_post( $args ); | |
update_option( 'bm_customer_group', $customer_group_new_id ); | |
update_post_meta( $customer_group_new_id, 'bm_all_products', 'on' ); | |
// Insert stored group settings | |
foreach ( $customer_group_data as $option_key => $option_value ) { | |
update_post_meta( $customer_group_new_id, $option_key, $option_value ); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment