所以我想在 WooCommerce 上運行一個 Tier 程式,我需要根據網站上的總花費向用戶顯示 Tier 級別。
我正在使用如何獲取用戶(客戶)在 WooCommerce 中花費的總金額?應答碼
我有 4 個級別,所以我想顯示用戶是否花費了超過 600 美元的一些文字,例如“恭喜你現在是 1 級”等等。
我感謝您的幫助
uj5u.com熱心網友回復:
您可以添加if條件。試試下面的代碼。
function get_user_total_spent( $atts ) {
extract( shortcode_atts( array(
'user_id' => get_current_user_id(),
), $atts, 'user_total_spent' ) );
if( $user_id > 0 ) {
$customer = new WC_Customer( $user_id ); // Get WC_Customer Object
$total_spent = $customer->get_total_spent(); // Get total spent amount
if( $total_spent > 600 && $total_spent < 1200 ){
$text = __( 'congrats you are now tier 1', 'woocommerce' );
}elseif( $total_spent > 1200 ){
$text = __( 'congrats you are now tier 2', 'woocommerce' );
}else{
$text = __( 'congrats you are now tier 3', 'woocommerce' );
}
$total_spent = wc_price( $total_spent );
return "Total Amount Spent: ".$total_spent." ".$text;
}
}
add_shortcode('user_total_spent', 'get_user_total_spent');
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/374955.html
標籤:php WordPress的 求购 短代码
上一篇:SQL在使用symfony遷移期間回傳語法錯誤或訪問沖突:1064
下一篇:在Laravel中找不到類“PhpOffice\phpspreadsheet\src\PhpSpreadsheet\Spreadsheet”
