I use the following code in my functions.php to redirect my WooCommerce 'order received' page to an custom URL:
// Redirect WooCommerce Order Received Page to Post
add_action( 'woocommerce_thankyou', 'rwl_redirectcustom');
function rwl_redirectcustom( $order_id ){
$order = wc_get_order( $order_id );
$url = 'https://my-website.com';
if ( ! $order->has_status( 'failed' ) ) {
wp_safe_redirect( $url );
exit;
}
}
Now I want to redirect instead to an static URL 'https://my-website.com' to a dynamic URL which is stored in an ACF field called 'paywall_post_url' of a post.
I have tried this
$url = get_permalink( get_post_meta( 'paywall_post_url' ) );
But this didn't worked. Where is my mistake?
Thanks
get_post_meta()
requires you to pass the post ID and meta key.
you want to use the acf functionget_field()
$url = get_permalink( get_field( 'paywall_post_url' ) );
this is if you saved the field as a post ID. otherwise it should be:
$url = get_field( 'paywall_post_url' );
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.