php WooCommerce重定向'收到订单'页面到ACF URL

dbf7pr2w  于 2022-12-21  发布在  PHP
关注(0)|答案(1)|浏览(117)

我在我的functions.php中使用以下代码将我的WooCommerce '收到订单'页面重定向到自定义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;
    }
}

现在我想重定向到一个静态URL 'my-website.com'到一个动态URL,它存储在一个叫做'paywall_post_url'的ACF字段中。
我试过这个

$url = get_permalink( get_post_meta( 'paywall_post_url' ) );

但这不起作用。我错在哪里?
谢啦,谢啦

q3qa4bjr

q3qa4bjr1#

get_post_meta()要求您传递帖子ID和 meta密钥。
你想使用acf函数get_field()

$url = get_permalink( get_field( 'paywall_post_url' ) );

如果您将字段保存为帖子ID,则为。否则应为:

$url = get_field( 'paywall_post_url' );

相关问题