Php 在WooCommerce产品简短描述中仅为来宾显示自定义文本
我想知道你是否能帮助我。我有下面的代码,它向我网站上的新访问者显示我在woocommerce中的产品简短描述上方的文本。根据文本执行所需的操作(创建帐户)后,我想隐藏文本,因为它不再需要 我真的很感激任何帮助Php 在WooCommerce产品简短描述中仅为来宾显示自定义文本,php,wordpress,woocommerce,product,logged,Php,Wordpress,Woocommerce,Product,Logged,我想知道你是否能帮助我。我有下面的代码,它向我网站上的新访问者显示我在woocommerce中的产品简短描述上方的文本。根据文本执行所需的操作(创建帐户)后,我想隐藏文本,因为它不再需要 我真的很感激任何帮助 add_filter('woocommerce_short_description','ts_add_text_short_descr'); function ts_add_text_short_descr($description){ echo 'To check if this
add_filter('woocommerce_short_description','ts_add_text_short_descr');
function ts_add_text_short_descr($description){
echo 'To check if this item qualifies for a discount <a href="https://www.livestainable.co.za/my-account-2/"><u><strong>Log In or Create</strong></u></a> an account.</br></br>';
return $description.$text;
}
add_filter('woocommerce_short_description','ts_add_text_short_descr');
函数ts_add_text_short_descr($description){
echo“检查此项目是否符合帐户折扣条件。”;
返回$description.$text;
}
要仅为来宾显示一些文本,只需使用!是否在IF
语句中登录了用户()
,如此重访代码中所示:
add_filter( 'woocommerce_short_description', 'add_text_before_short_description_for_guests' );
function add_text_before_short_description_for_guests( $description ) {
// Only for guest users
if ( ! is_user_logged_in() ) {
$description = '<p>' . sprintf( __( "To check if this item qualifies for a discount %s an account."), '<a href="https://www.livestainable.co.za/my-account-2/"><u><strong>' . __("Log In or Create") . '</strong></u></a>' ) . '</p>' . $description;
}
return $description;
}
add_filter('woocommerce_short_description','add_text_before_short_description_for_guest');
函数为来宾在简短描述之前添加文本($description){
//仅适用于来宾用户
如果(!用户是否已登录()){
$description=''.sprintf(uuuu(“检查此项目是否符合%s帐户的折扣条件”),''。'.$description;
}
返回$description;
}
代码进入活动子主题(或活动主题)的functions.php文件。经过测试,效果良好。太棒了,非常感谢。它对我非常有效。