WooCommerce 控制產品頁面結構的模版位於 WooCommerce/templates/single-product 目錄下,本文介紹讓產品圖片顯示為原圖,並移除圖片連結的方法。
改變產品圖片尺寸
WordPress 預設的圖片尺寸有 thumbnail, medium, large 和 full, WooCommerce 預設的產品圖片尺寸是 shop_single 。下面程式碼演示如何將產品圖片尺寸從 shop_single 改成 full,即顯示原圖片。
add_filter( 'single_product_large_thumbnail_size', 'wc_single_product_size' ); function wc_single_product_size(){ return 'full'; }
移除產品圖片連結
add_filter( 'WooCommerce_single_product_image_html', 'wc_remove_product_image_url' ); function wc_remove_product_image_url( $html ){ return strip_tags( $html, '<img>'); }
關於文中用到的 filters,參考 WooCommerce 模版目錄下的 product-image.php 檔案。