如何将免费标签更改为请求价格,并在用户登录时包含请求价格的按钮


How to change the FREE label to Price on Request and include a button to request a price if the user is logged in

我已经把它放在了我的functions.php中,它很有效,显示了联系人表单7的提交按钮来代替"免费!",但我似乎无法正确使用if语句来禁用未登录用户的按钮。有什么东西我错过了吗?

//remove free when 0
add_filter( 'woocommerce_variable_free_price_html','remove_free_price_text' );
add_filter( 'woocommerce_free_price_html','remove_free_price_text' );
add_filter( 'woocommerce_variation_free_price_html','remove_free_price_text' );
function remove_free_price_text( $price ) {
if ( is_user_logged_in() )  
echo do_shortcode( '[contact-form-7 id="3696" title="Request Price"]' );
elseif ( !is_user_logged_in() )
return 'Price Upon Request';        
}

尝试

if ( is_user_logged_in() ){
   echo do_shortcode( '[contact-form-7 id="3696" title="Request Price"]' );
}else{
   echo('Price Upon Request');
}