{"id":528890,"date":"2021-11-09T13:47:31","date_gmt":"2021-11-09T05:47:31","guid":{"rendered":"https:\/\/loyseo.com\/code-snippet\/woocommerce%ef%bc%9a%e5%a6%82%e4%bd%95%e7%b5%a6%e7%94%a2%e5%93%81%e6%b8%85%e5%96%ae%e7%9a%84%e9%a0%90%e8%a8%ad%e6%8e%92%e5%ba%8f%e5%88%aa%e9%99%a4%e3%80%81%e9%87%8d%e5%91%bd%e5%90%8d\/"},"modified":"2023-08-25T14:39:48","modified_gmt":"2023-08-25T06:39:48","slug":"woocommerce-remove-rename-add-sorting-options-shop","status":"publish","type":"code-snippet","link":"https:\/\/loyseo.com\/zh-hant\/code-snippet\/woocommerce-remove-rename-add-sorting-options-shop\/","title":{"rendered":"WooCommerce\uff1a\u5982\u4f55\u7d66\u7522\u54c1\u5217\u8868\u7684\u201c\u9810\u8a2d\u6392\u5e8f\u201d\u522a\u9664\u3001\u91cd\u547d\u540d\u3001\u6dfb\u52a0\u7684\u6392\u5e8f\u9078\u9805"},"content":{"rendered":"\n<p>\u6211\u5011\u4e4b\u524d\u5df2\u7d93\u8aaa\u904e\uff1a<a href=\"https:\/\/loyseo.com\/zh-hant\/code-snippet\/woocommerce-how-to-remove-the-default-sorting-dropdown\/\">\u5982\u4f55\u5b8c\u5168\u522a\u9664 WooCommerce \u5546\u5e97\u3001\u7522\u54c1\u5217\u8868\u9801\u9762\u4e2d\u986f\u793a\u7684\u201c\u9810\u8a2d\u6392\u5e8f\u201d\u4e0b\u62c9\u9078\u9805<\/a>\u3002<\/p>\n\n<p>\u4f46\u662f\uff0c\u6709\u6642\u4f60\u53ef\u80fd\u53ea\u9700\u8981\u522a\u9664\u9810\u8a2d\u9078\u9805\u4e2d\u7684\u4e00\u500b\uff0c\u6216\u8005\u91cd\u547d\u540d\u9019\u4e9b\u9078\u9805\uff0c\u751a\u81f3\u662f\u6dfb\u52a0\u65b0\u7684\u6392\u5e8f\u9078\u9805\u3002 \u50cf\u5f80\u5e38\u4e00\u6a23\uff0c\u591a\u8667\u4e86 WooCommerce \u6302\u9264\u548c\u7be9\u6aa2\u7a0b\u5f0f\uff0c\u5e7e\u884c PHP \u4ee3\u78bc\u5c31\u53ef\u4ee5\u5be6\u73fe\u9019\u500b\u76ee\u6a19\u3002<\/p>\n\n<figure class=\"wp-block-image\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"534\" src=\"https:\/\/loyseo.com\/wp-content\/uploads\/2021\/11\/woocommerce-default-sorting-option-add-remove-edit.png\" alt=\"\" class=\"wp-image-513431\" title=\"-\"><figcaption>\u522a\u9664\u3001\u91cd\u547d\u540d\u6216\u6dfb\u52a0\u9078\u9805\u5230 WooCommerce\u201c\u9810\u8a2d\u6392\u5e8f\u201d\u4e0b\u62c9\u5217\u8868<br\/><\/figcaption><\/figure>\n\n<h2 class=\"wp-block-heading\">PHP \u4ee3\u78bc\u6bb5 #1\uff1a\u5728WooCommerce\u7522\u54c1\u5217\u8868\u4e2d\u522a\u9664\u67d0\u500b\u6392\u5e8f\u9078\u9805<\/h2>\n\n<div class=\"wp-block-syntaxhighlighter-code \">\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\/**\n* @snippet       Remove Sorting Option @ WooCommerce Shop\n* @testedwith    WooCommerce 3.8\n*\/\nadd_filter( 'woocommerce_catalog_orderby', 'bbloomer_remove_sorting_option_woocommerce_shop' );\nfunction bbloomer_remove_sorting_option_woocommerce_shop( $options ) {\nunset( $options['rating'] );\nreturn $options;\n}\n\/\/\u8bf4\u660e\uff1a\u4f60\u53ef\u4ee5\u901a\u8fc7\u6dfb\u52a0\u66f4\u591a\u7684 \"unset \"\u8c03\u7528\u6765\u5220\u9664\u5176\u4ed6\u6392\u5e8f\u9009\u9879......\u8fd9\u91cc\u6709\u4e00\u4e2a\u9009\u9879\u5217\u8868: 'menu_order', 'popularity', 'rating', 'date', 'price', 'price-desc'\n<\/pre>\n<\/div>\n\n<h2 class=\"wp-block-heading\">PHP \u4ee3\u78bc\u6bb5 #2\uff1a\u5728WooCommerce\u7522\u54c1\u5217\u8868\u4e2d\u7d66\u6392\u5e8f\u9078\u9805\u91cd\u547d\u540d<\/h2>\n\n<div class=\"wp-block-syntaxhighlighter-code \">\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\/**\n* @snippet       Rename a Sorting Option @ WooCommerce Shop\n* @testedwith    WooCommerce 3.8\n*\/\nadd_filter( 'woocommerce_catalog_orderby', 'bbloomer_rename_sorting_option_woocommerce_shop' );\nfunction bbloomer_rename_sorting_option_woocommerce_shop( $options ) {\n$options['price'] = 'Sort by price (asc)';\nreturn $options;\n}\n<\/pre>\n<\/div>\n\n<h2 class=\"wp-block-heading\">PHP \u4ee3\u78bc\u6bb5 #3\uff1a\u5728 WooCommerce \u7522\u54c1\u5217\u8868\u4e2d\u6dfb\u52a0\u81ea\u5b9a\u7fa9\u6392\u5e8f\u9078\u9805<\/h2>\n\n<p>\u5728\u6b64\u793a\u4f8b\u4e2d\uff0c\u6211\u5011\u5c07\u5275\u5efa\u4e00\u500b\u540d\u70ba\u201cSort by name \uff08desc\uff09\u201d\u7684\u65b0\u6392\u5e8f\u9078\u9805\uff0c\u5b83\u6703\u6309\u7522\u54c1\u7684\u6a19\u984c\uff08\u964d\u5e8f\uff09\u5c0d\u7522\u54c1\u9032\u884c\u6392\u5e8f\u3002<\/p>\n\n<div class=\"wp-block-syntaxhighlighter-code \">\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\/**\n* @snippet       Add a Custom Sorting Option @ WooCommerce Shop\n* @testedwith    WooCommerce 4.0\n*\/\n\/\/ 1. \u521b\u5efa\u4e00\u4e2a\u4ea7\u54c1\u6392\u5e8f\u89c4\u5219\nadd_filter( 'woocommerce_get_catalog_ordering_args', 'bbloomer_sort_by_name_woocommerce_shop' );\nfunction bbloomer_sort_by_name_woocommerce_shop( $args ) {\n$orderby_value = isset( $_GET['orderby'] ) ? wc_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );\nif ( 'name' == $orderby_value ) {\n$args['orderby'] = 'title';\n$args['order'] = 'DESC';\n}\nreturn $args;\n}\n\/\/ 2. \u5c06\u4ea7\u54c1\u6392\u5e8f\u89c4\u5219\u52a0\u5165\u5230\u6392\u5e8f\u4e0b\u62c9\u9009\u9879\u4e2d\nadd_filter( 'woocommerce_catalog_orderby', 'bbloomer_load_custom_woocommerce_catalog_sorting' );\nfunction bbloomer_load_custom_woocommerce_catalog_sorting( $options ) {\n$options['name'] = 'Sort by name (desc)';\nreturn $options;\n}\n<\/pre>\n<\/div>\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6211\u5011\u4e4b\u524d\u5df2\u7d93\u8aaa\u904e\uff1a\u5982\u4f55\u5b8c\u5168\u522a\u9664 WooCommerce \u5546\u5e97\u3001\u7522\u54c1\u5217\u8868\u9801\u9762\u4e2d\u986f\u793a\u7684\u201c\u9810\u8a2d\u6392\u5e8f\u201d\u4e0b\u62c9\u9078\u9805\u3002 \u4f46\u662f\uff0c\u6709\u6642\u4f60\u53ef\u80fd\u53ea\u9700\u8981\u522a\u9664\u9810\u8a2d\u9078\u9805\u4e2d\u7684\u4e00\u500b\uff0c\u6216\u8005\u91cd\u547d\u540d\u9019\u4e9b\u9078\u9805\uff0c\u751a\u81f3\u662f\u6dfb\u52a0\u65b0\u7684\u6392\u5e8f\u9078\u9805\u3002 \u50cf\u5f80\u5e38\u4e00\u6a23\uff0c\u591a\u8667\u4e86 WooCommerce \u6302\u9264\u548c\u7be9\u6aa2\u7a0b\u5f0f\uff0c\u5e7e\u884c PHP \u4ee3\u78bc\u5c31\u53ef\u4ee5\u5be6\u73fe\u9019\u500b\u76ee\u6a19\u3002 PHP \u4ee3\u78bc\u6bb5 #1\uff1a\u5728WooCommerce\u7522\u54c1\u5217\u8868\u4e2d\u522a\u9664\u67d0\u500b\u6392\u5e8f\u9078\u9805 \/** * @snippet  [&hellip;]<\/p>\n","protected":false},"featured_media":0,"template":"","class_list":["post-528890","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\/528890","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=528890"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}