Woocommerce – Change order of products in Confirmed Order

Using a clean wordpress install, woocommerce and storefront theme, I came up with this code. It sorts regular products and variable products only. Only sorts in admin panel. Sorts by weight from hgih to low (you can see the commented section, you can uncomment the relevant option to you). The code goes into functions.php add_filter(‘woocommerce_order_get_items’, … Read more

Get category slug of the Parent category of a Product

Put this below code in functions.php and Try it. add_action( ‘woocommerce_before_single_product’, ‘content_before_addtocart_button’ ); function content_before_addtocart_button() { global $post; $categories = array(); $taxonomies = get_terms( array( ‘taxonomy’ => ‘product_cat’, ‘hide_empty’ => false, ‘parent’ => 0 )); if ( !empty($taxonomies) ) : foreach( $taxonomies as $taxonomy ) { $categories[] = $taxonomy->slug; } endif; $terms = get_the_terms( $post->ID, … Read more

localize_script but data changes dependent on product ID

You should call wp_localize_script() in the wp_enqueue_scripts hook (or a later hook) in which you would get the correct product/post data such as ID, and that conditional tags like is_single() would also work as expected. So you should move all the $product, $product_id, $dataToBePassed and wp_localize_script() parts to inside the wp_enqueue_scripts callback, and then you’d … Read more

Woocommerce : Add name filed of checkout page to buyers wordpress display name

The second part of the problem is solved by putting this code into theme’s functions.php file : // First name as default display name add_action( ‘profile_update’, ‘set_display_name’, 10 ); function set_display_name( $user_id ) { $data = get_userdata( $user_id ); if($data->first_name) { remove_action( ‘profile_update’, ‘set_display_name’, 10 ); // profile_update is called by wp_update_user, so we need … Read more