WooCommerce : 顯示產品頁面上銷售的產品數量

在主題的functions.php中加入如下程式碼

//在shop頁面顯示總銷量
add_action( ‘woocommerce_after_shop_loop_item_title’, ‘wc_product_sold_count’, 5 );
//在產品詳情頁面顯示總銷量
add_action( ‘woocommerce_single_product_summary’, ‘wc_product_sold_count’, 11 );

function wc_product_sold_count() {
global $product;
$units_sold = get_post_meta( $product->id, ‘total_sales’, true );
echo ‘<p>’ . sprintf( __( ‘已銷售: %s’, ‘woocommerce’ ), $units_sold ) . ‘</p>’;
}

修改add_action最後的數字可以調整位置,值越大越靠後。

如果您正在尋找 屏東網站設計公司
我們能協助您打造一個兼具美感與行銷效益的網站,讓您的品牌在線上發光發熱。

尋找屏東網站設計公司?選擇炬輝設計

📌 #名片設計 #平面設計 #網頁設計 #粉絲團代管
🌐 官方網站:https://juhui.com.tw/
📱 Facebook:https://facebook.com/