Woocommerce Support… or help with custom code please
-
Hi, not sure this is the right place to ask but… I’ll try.
I’m writing to ask if Woocommerce support is planned;
I’d like to give badges based on woocommerce purchases.EXAMPLE:
When you buy “ITEM A”, a badge is created (if not existing already) named “ITEM A OWNER”, keeping excerpt and featured image from the product.
I’m doing this thing semi-manually with some code I put together, and it seems to work decently… but I’m NOT a developer and I’m sure one could do MUCH better. It’s little more than a feeling, but I’m afraid my code sucks. ??
Basically, what I do is:
“on order complete, if the purchased product is X, award achievement Y”
but the achievement and the product both have to exist already, and I have to identify every single product and every single achievement by ID. SO annoying…
I create products and achievements in bulk, then I add rules accordingly, to the following code:
add_action('woocommerce_payment_complete', 'custom_process_order', 10, 1); function custom_process_order($order_id) { $order = new WC_Order( $order_id ); $myuser_id = (int)$order->user_id; $user_info = get_userdata($myuser_id); $items = $order->get_items(); foreach ($items as $item) { if ($item['product_id']==XXX) { badgeos_award_achievement_to_user( xxx, $myuser_id ); } if ($item['product_id']==YYY) { badgeos_award_achievement_to_user( yyy, $myuser_id ); } if ($item['product_id']==ZZZ) { badgeos_award_achievement_to_user( zzz, $myuser_id ); } // AND SO ON, IF PRODUCT IS X, ACHIEVEMENT IS Y // } return $order_id; }
If this kind of feature is going to be supported with an addon, well, GREAT!
Otherwise, can I get some help to improve my code?
I’m not afraid to keep working almost manually, but at least a help would be VERY appreciated… it would be bad if such code generates major bugs or security issues. ??THANKS ANYWAY and keep on with the good work! ^_^
- The topic ‘Woocommerce Support… or help with custom code please’ is closed to new replies.