Redirecting to home page after login as custom role WordPress

This is what I’m using, it redirects “shop_managers” to the admin orders page. function my_login_redirect( $redirect_to, $request, $user ){ if (isset($user->roles) && is_array($user->roles)) { if (in_array(‘shop_manager’, $user->roles)) { $redirect_to = ‘/wp-admin/edit.php?post_type=shop_order’; } } return $redirect_to; } add_filter( ‘login_redirect’, ‘my_login_redirect’, 10, 3 ); Obviously, you will need to change ‘shop_managers’ and ‘/wp-admin/edit.php?post_type=shop_order’ to what you need. … Read more

Get first URL from post content

I think this question might put you in the right direction. In case that link is broken, here’s the answer as provided by Jon Fabry in that thread. $post_link = get_the_permalink(); if ( preg_match(‘/<a (.+?)>/’, get_the_content(), $match) ) { $link = array(); foreach ( wp_kses_hair($match[1], array(‘http’)) as $attr) { $link[$attr[‘name’]] = $attr[‘value’]; } $post_link = … Read more

Set a condition based on WooCommerce checkout city field while placing order

Updated The following code will add an additional recipient based on customer billing/shipping city, to new order admin notification: add_filter( ‘woocommerce_email_recipient_new_order’, ‘different_email_recipients’, 10, 2 ); function different_email_recipients( $recipient, $order ) { if ( ! is_a( $order, ‘WC_Order’ ) ) return $recipient; $city = $order->get_shipping_city(); $city = empty( $city ) ? $order->get_billing_city() : $city; // Conditionaly … Read more

Woocommerce redirect thankyou page based on product ID doesn’t empty Cart

Your actual code is a bit outdated and not so secure… Since WooCommerce 3 Order items are now Objects and $item[‘product_id’] is replaced by $item->get_product_id(). You should try first to use woocommerce_get_return_url like: add_action( ‘woocommerce_get_return_url’, ‘custom_order_received_return_url’, 10, 2 ); function custom_order_received_redirect( $return_url, $order ){ // HERE define your products IDs in the array $product_ids = … Read more

Custom Text in WooCommerce Order Processing Email Based on Products

Try something like this: <?php $order_id = $order->get_id(); $order = wc_get_order( $order_id ); $items = $order->get_items(); $is_valid = null; foreach ( $items as $item_id => $item_data ) { $product = $item_data->get_product(); $categories = array(); $terms = get_the_terms( $product->get_id(), ‘product_cat’ ); if ( is_wp_error( $terms ) || empty( $terms ) ) { continue; } foreach ( … Read more

Make the first item as default on Woocommerce product category items list

Try the following improved code, to get “active” on the first item: <?php $product_cats = get_terms([ ‘taxonomy’ => ‘product_cat’, ‘hide_empty’ => true, ‘parent’ => 0, ‘fields’ => ‘names’ // Term names ]); foreach ( $product_cats as $key => $parent_term_name ) { printf( ‘<button class=”tablinks %s” onclick=”%s”>%s</button>’, $key === 0 ? esc_attr( ‘active’ ) : ”, … Read more

Get stock by custom meta field on all Woocommerce variable products

The following function will give you an array with the calculated stock quantity from all product variations for each custom meta field “Brand” value, using WPDB Class (a SQL query): global $wpdb; $results = $wpdb->get_results( ” SELECT pm.meta_value as brand, SUM(pm2.meta_value) as stock FROM {$wpdb->prefix}postmeta pm INNER JOIN {$wpdb->prefix}posts p ON pm.post_id = p.post_parent INNER … Read more

Custom Theme, Custom shortcode not working

I would recommend using single quotes if you want to include some HTML, also you need to return something otherwise nothing happens. // WP Shortcode function text_shortcode() { return ‘<strong>bold text:</strong> <a href=”https://wordpress.stackexchange.com/questions/318934/shortcode-returns-escaped-html-tags”>See wordpress.stackexchange.com</a>’; } add_shortcode(‘bold-text’, ‘text_shortcode’); Your WordPress shortcode would be: [bold-text] See my other answers with examples: – Shortcode created to check language … Read more