Setting custom canonical urls

It depends on how your canonical URLs are being written to the page. In your theme’s header you may find something like: <link rel=”canonical” href=”https://wordpress.stackexchange.com/questions/331598/<?php echo get_permalink(); ?>”> If you are able to edit your theme (or child theme if using a distributed theme) you can put whatever you want there instead. For instance, you … 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