{"id":528896,"date":"2021-04-12T19:33:32","date_gmt":"2021-04-12T11:33:32","guid":{"rendered":"https:\/\/loyseo.com\/code-snippet\/%e5%a6%82%e4%bd%95%e5%9c%a8woocommerce%e7%94%a2%e5%93%81%e6%b8%85%e5%96%ae%e4%b8%ad%e5%b1%95%e7%a4%ba%e8%ae%8a%e9%ab%94%e7%94%a2%e5%93%81%e7%9a%84%e6%9c%80%e4%bd%8e%e5%83%b9%e6%a0%bc\/"},"modified":"2024-06-22T17:56:52","modified_gmt":"2024-06-22T09:56:52","slug":"woocommerce-display-lowest-price-on-category-archive-page-only","status":"publish","type":"code-snippet","link":"https:\/\/loyseo.com\/zh-hant\/code-snippet\/woocommerce-display-lowest-price-on-category-archive-page-only\/","title":{"rendered":"\u5982\u4f55\u5728WooCommerce\u7522\u54c1\u5217\u8868\u4e2d\u5c55\u793a\u8b8a\u9ad4\u7522\u54c1\u7684\u6700\u4f4e\u50f9\u683c"},"content":{"rendered":"\n<p>\u6211\u5011\u5728\u7528WooCommerce\u9032\u884c<a href=\"\/\" class=\"rank-math-link\">\u67b6\u8a2d\u4f01\u696d\u7db2\u7ad9<\/a>\u6642\uff0c\u5982\u679c\u92b7\u552e\u7684\u67d0\u7522\u54c1\u5b58\u5728\u591a\u7a2e\u5c6c\u6027\u4e14\u50f9\u683c\u4e0d\u540c\uff0c\u90a3\u9ebc\u5728\u7522\u54c1\u5217\u8868\u548c\u7522\u54c1\u8a73\u60c5\u4e2d\u67e5\u770b\u5230\u8a72\u7522\u54c1\u50f9\u683c\u5c07\u6703\u662f\u4e00\u500b\u5340\u9593\uff0c\u683c\u5f0f\u662f\uff1a\u6700\u4f4e\u50f9~\u6700\u9ad8\u50f9\u3002 \u5982\u679c\u4f60\u5e0c\u671b\u5728\u7522\u54c1\u5217\u8868\u9801\u4e2d\u50c5\u5c55\u793a\u7522\u54c1\u7684\u6700\u4f4e\u50f9\uff0c\u800c\u5728\u7522\u54c1\u8a73\u60c5\u9801\u9084\u4fdd\u6301\u5340\u9593\u50f9\u5c55\u793a\uff0c\u90a3\u9ebc\u4e0b\u9762\u9019\u6bb5\u4ee3\u78bc\u5c31\u80fd\u5920\u5be6\u73fe\u4f60\u7684\u9700\u6c42\u3002<\/p>\n\n<p>\u9996\u5148\uff0c\u8acb\u5b89\u88dd<a href=\"https:\/\/loyseo.com\/zh-hant\/plugins\/code-snippets\/\" class=\"rank-math-link\">Code Snippet<\/a>\u5916\u639b<\/p>\n\n<p>\u7136\u5f8c\uff0c\u6dfb\u52a0\u4e00\u500bsnippet\uff0c\u5c07\u4e0b\u65b9\u4ee3\u78bc\u8907\u88fd\u9032\u53bb<\/p>\n\n<pre class=\"wp-block-code\"><code>\/\/ Show only lowest prices in WooCommerce variable products\n\nadd_filter( 'woocommerce_variable_sale_price_html', 'wpglorify_variation_price_format', 10, 2 );\nadd_filter( 'woocommerce_variable_price_html', 'wpglorify_variation_price_format', 10, 2 );\n \nfunction wpglorify_variation_price_format( $price, $product ) {\n    if (is_product_category() ) {\n \n\/\/ Main Price\n$prices = array( $product-&gt;get_variation_price( 'min', true ), $product-&gt;get_variation_price( 'max', true ) );\n$price = $prices&#91;0] !== $prices&#91;1] ? sprintf( __( '%1$s', 'woocommerce' ), wc_price( $prices&#91;0] ) ) : wc_price( $prices&#91;0] );\n \n\/\/ Sale Price\n$prices = array( $product-&gt;get_variation_regular_price( 'min', true ), $product-&gt;get_variation_regular_price( 'max', true ) );\nsort( $prices );\n$saleprice = $prices&#91;0] !== $prices&#91;1] ? sprintf( __( '%1$s', 'woocommerce' ), wc_price( $prices&#91;0] ) ) : wc_price( $prices&#91;0] );\n \nif ( $price !== $saleprice ) {\n$price = '&lt;del&gt;' . $saleprice . $product-&gt;get_price_suffix() . '&lt;\/del&gt; &lt;ins&gt;' . $price . $product-&gt;get_price_suffix() . '&lt;\/ins&gt;';\n}\n\t}\nreturn $price;\n}<\/code><\/pre>\n\n<p>\u6dfb\u52a0\u5b8c\u5f8c\u5c31\u662f\u4e0b\u5716\u6240\u793a\u7684\u6a21\u6a23\u3002<\/p>\n\n<figure class=\"wp-block-image size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1591\" height=\"911\" src=\"https:\/\/loyseo.com\/wp-content\/uploads\/2021\/04\/image.png\" alt=\"&#x5982;&#x4F55;&#x5728;WooCommerce&#x7522;&#x54C1;&#x6E05;&#x55AE;&#x4E2D;&#x5C55;&#x793A;&#x8B8A;&#x9AD4;&#x7522;&#x54C1;&#x7684;&#x6700;&#x4F4E;&#x50F9;&#x683C;\" class=\"wp-image-509985\" title=\"-\"><\/figure>\n\n<p>\u67e5\u770b\u66f4\u591a<a href=\"https:\/\/loyseo.com\/zh-hant\/tutorial\/woocommerce\/\" data-type=\"tutorial\" data-id=\"530952\">WooCommerce\u6559\u5b78<\/a>\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6211\u5011\u5728\u7528WooCommerce\u9032\u884c\u67b6\u8a2d\u4f01\u696d\u7db2\u7ad9\u6642\uff0c\u5982\u679c\u92b7\u552e\u7684\u67d0\u7522\u54c1\u5b58\u5728\u591a\u7a2e\u5c6c\u6027\u4e14\u50f9\u683c\u4e0d\u540c\uff0c\u90a3\u9ebc\u5728\u7522\u54c1\u5217\u8868\u548c\u7522\u54c1\u8a73\u60c5\u4e2d\u67e5\u770b\u5230\u8a72\u7522\u54c1\u50f9\u683c\u5c07\u6703\u662f\u4e00\u500b\u5340\u9593\uff0c\u683c\u5f0f\u662f\uff1a\u6700\u4f4e\u50f9~\u6700\u9ad8\u50f9\u3002 \u5982\u679c\u4f60\u5e0c\u671b\u5728\u7522\u54c1\u5217\u8868\u9801\u4e2d\u50c5\u5c55\u793a\u7522\u54c1\u7684\u6700\u4f4e\u50f9\uff0c\u800c\u5728\u7522\u54c1\u8a73\u60c5\u9801\u9084\u4fdd\u6301\u5340\u9593\u50f9\u5c55\u793a\uff0c\u90a3\u9ebc\u4e0b\u9762\u9019\u6bb5\u4ee3\u78bc\u5c31\u80fd\u5920\u5be6\u73fe\u4f60\u7684\u9700\u6c42\u3002 \u9996\u5148\uff0c\u8acb\u5b89\u88ddCode Snippet\u5916\u639b \u7136\u5f8c\uff0c\u6dfb\u52a0\u4e00\u500bsnippet\uff0c\u5c07\u4e0b\u65b9\u4ee3\u78bc\u8907\u88fd\u9032\u53bb \u6dfb\u52a0\u5b8c\u5f8c\u5c31\u662f\u4e0b\u5716\u6240\u793a [&hellip;]<\/p>\n","protected":false},"featured_media":0,"template":"","class_list":["post-528896","code-snippet","type-code-snippet","status-publish","hentry"],"acf":[],"taxonomy_info":[],"featured_image_src_large":false,"author_info":[],"comment_info":"","_links":{"self":[{"href":"https:\/\/loyseo.com\/zh-hant\/wp-json\/wp\/v2\/code-snippet\/528896","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/loyseo.com\/zh-hant\/wp-json\/wp\/v2\/code-snippet"}],"about":[{"href":"https:\/\/loyseo.com\/zh-hant\/wp-json\/wp\/v2\/types\/code-snippet"}],"wp:attachment":[{"href":"https:\/\/loyseo.com\/zh-hant\/wp-json\/wp\/v2\/media?parent=528896"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}