{"id":528889,"date":"2023-04-13T14:20:35","date_gmt":"2023-04-13T06:20:35","guid":{"rendered":"https:\/\/loyseo.com\/code-snippet\/woocommerce%ef%bc%9a%e5%9c%a8%e7%b7%a8%e8%bc%af%e8%a8%82%e5%96%ae%e9%a0%81%e9%9d%a2%ef%bc%8c%e7%82%ba%e5%b8%b3%e5%96%ae%e4%bd%8d%e5%9d%80%e3%80%81%e9%85%8d%e9%80%81%e5%9c%b0%e5%9d%80%e3%80%81%e9%83%b5\/"},"modified":"2023-08-25T14:38:58","modified_gmt":"2023-08-25T06:38:58","slug":"add-copy-to-woocommerce-edit-order-page","status":"publish","type":"code-snippet","link":"https:\/\/loyseo.com\/zh-hant\/code-snippet\/add-copy-to-woocommerce-edit-order-page\/","title":{"rendered":"WooCommerce\uff1a\u5728\u7de8\u8f2f\u8a02\u55ae\u9801\u9762\uff0c\u70ba\u5e33\u55ae\u4f4d\u5740\u3001\u914d\u9001\u5730\u5740\u3001\u90f5\u7bb1\u3001\u96fb\u8a71\u6dfb\u52a0\u4e00\u9375\u8907\u88fd\u6587\u6848\u7684\u529f\u80fd"},"content":{"rendered":"\n<p>\u6211\u6709\u4e00\u4f4dB2C\u8de8\u5883\u96fb\u5546\u96f6\u552e\u7ad9\u7684<a href=\"\/\">\u67b6\u8a2d\u7db2\u7ad9<\/a>\u5ba2\u6236\uff0c\u5728\u904b\u71df\u6642\uff0c\u6709\u4e00\u500b\u5c0f\u9700\u6c42\uff1a\u5e0c\u671b\u80fd\u5728<a href=\"https:\/\/loyseo.com\/zh-hant\/tutorial\/woocommerce\/woocommerce-manage-orders\/\" data-type=\"post\" data-id=\"515021\">WooCommerce\u7684\u8a02\u55ae<\/a>\u8a73\u60c5\u9801\u9762\u4e2d\uff0c\u80fd\u5920\u5c07Billing\uff08\u5e33\u55ae\u4f4d\u5740\uff09\u3001Shipping\uff08\u914d\u9001\u5730\u5740\uff09\u986f\u793a\u5728\u4e00\u884c\u4e2d\uff0c\u9019\u6a23\u65b9\u4fbf\u8907\u88fd\u5230\u81ea\u5df1\u7684ERP\u7cfb\u7d71\u4e2d\u9032\u884c\u7ba1\u7406\u3002<\/p>\n\n<p>\u8003\u616e\u5230\u6700\u7d42\u76ee\u7684\u662f\u70ba\u4e86\u8907\u88fd\uff0c\u90a3\u9ebc\u6dfb\u52a0\u4e00\u9375\u8907\u88fd\u5e33\u55ae\u4f4d\u5740\u3001\u914d\u9001\u4f4d\u5740\u7684\u529f\u80fd\u5c31\u53ef\u4ee5\u4e86\uff0c\u9806\u5e36\u7d66\u90f5\u7bb1\u548c\u96fb\u8a71\u4e5f\u6dfb\u52a0\u4e00\u9375\u8907\u88fd\u7684\u529f\u80fd\u3002 \u65bc\u662f\uff0c\u4e0b\u5716\u4fbf\u662f\u6700\u7d42\u7684\u6548\u679c\u5566\uff0c\u5b83\u662f\u600e\u9ebc\u5be6\u73fe\u7684\u5462\uff1f \u4e0d\u9700\u8981\u85c9\u52a9\u5c08\u9580\u7684\u5916\u639b\u7a0b\u5f0f\uff0c\u6211\u5011\u7528\u4e00\u6bb5PHP\u4ee3\u78bc\u5c31\u53ef\u4ee5\u641e\u5b9a\u5b83\u3002<\/p>\n\n<figure class=\"wp-block-image size-full\"><img fetchpriority=\"high\" decoding=\"async\" width=\"2345\" height=\"717\" src=\"https:\/\/loyseo.com\/wp-content\/uploads\/2023\/04\/add-copy-to-woocommerce-edit-order-page-billing-shipping-address.png\" alt=\"WooCommerce&#xFF1A;&#x5728;&#x7DE8;&#x8F2F;&#x8A02;&#x55AE;&#x9801;&#x9762;&#xFF0C;&#x70BA;&#x5E33;&#x55AE;&#x4F4D;&#x5740;&#x3001;&#x914D;&#x9001;&#x5730;&#x5740;&#x3001;&#x90F5;&#x7BB1;&#x3001;&#x96FB;&#x8A71;&#x6DFB;&#x52A0;&#x4E00;&#x9375;&#x8907;&#x88FD;&#x6587;&#x6848;&#x7684;&#x529F;&#x80FD;\" class=\"wp-image-519572\" title=\"-\" srcset=\"https:\/\/loyseo.com\/wp-content\/uploads\/2023\/04\/add-copy-to-woocommerce-edit-order-page-billing-shipping-address.png 2345w, https:\/\/loyseo.com\/wp-content\/uploads\/2023\/04\/add-copy-to-woocommerce-edit-order-page-billing-shipping-address-450x138.png 450w, https:\/\/loyseo.com\/wp-content\/uploads\/2023\/04\/add-copy-to-woocommerce-edit-order-page-billing-shipping-address-1000x306.png 1000w\" sizes=\"(max-width: 2345px) 100vw, 2345px\" \/><\/figure>\n\n<p>\u8acb\u5728<a href=\"https:\/\/loyseo.com\/code-snippet\/\">Code snippet<\/a>\u5916\u639b\u7a0b\u5f0f\u4e2d\u65b0\u589e\u4e26\u555f\u7528\u4e0b\u9762\u9019\u6bb5php\u4ee3\u78bc\u6bb5\uff0c\u6ce8\u610f\uff0c\u53ef\u4ee5\u8a2d\u7f6e\u70ba\uff1aOnly run in administration area\uff1a<\/p>\n\n<pre class=\"wp-block-code\"><code>\/\/ Add \"Copy\" button next to email and phone fields on order edit page\nadd_action( 'woocommerce_admin_order_data_after_billing_address', 'add_copy_buttons_to_order_email_and_phone', 10, 1 );\nfunction add_copy_buttons_to_order_email_and_phone( $order ) {\n    $email = $order->get_billing_email();\n    $phone = $order->get_billing_phone();\n    ?>\n    &lt;button type=\"button\" class=\"button copy-email\" data-clipboard-text=\"&lt;?php echo $email; ?>\">Copy Email&lt;\/button>\n    &lt;button type=\"button\" class=\"button copy-phone\" data-clipboard-text=\"&lt;?php echo $phone; ?>\">Copy Phone&lt;\/button>\n    &lt;script>\n    jQuery(document).ready(function($) {\n        var clipboard = new ClipboardJS('.copy-email, .copy-phone');\n    });\n    &lt;\/script>\n    &lt;?php\n}\n\/\/ Add \"Copy\" button next to billing and shipping addresses on order edit page and replace &lt;br\/> with comma\nadd_action( 'woocommerce_admin_order_data_after_billing_address', 'add_copy_button_to_billing_address', 10, 1 );\nadd_action( 'woocommerce_admin_order_data_after_shipping_address', 'add_copy_button_to_shipping_address', 10, 1 );\nfunction add_copy_button_to_billing_address( $order ) {\n    $billing_address = $order->get_formatted_billing_address();\n    $billing_address = str_replace( '&lt;br\/>', ', ', $billing_address );\n    ?>\n    &lt;button type=\"button\" class=\"button copy-billing-address\" data-clipboard-text=\"&lt;?php echo $billing_address; ?>\">Copy Billing Address&lt;\/button>\n    &lt;script>\n    jQuery(document).ready(function($) {\n        var clipboard = new ClipboardJS('.copy-billing-address');\n    });\n    &lt;\/script>\n    &lt;?php\n}\nfunction add_copy_button_to_shipping_address( $order ) {\n    $shipping_address = $order->get_formatted_shipping_address();\n    $shipping_address = str_replace( '&lt;br\/>', ', ', $shipping_address );\n    ?>\n    &lt;button type=\"button\" class=\"button copy-shipping-address\" data-clipboard-text=\"&lt;?php echo $shipping_address; ?>\">Copy Shipping Address&lt;\/button>\n    &lt;script>\n    jQuery(document).ready(function($) {\n        var clipboard = new ClipboardJS('.copy-shipping-address');\n    });\n    &lt;\/script>\n    &lt;?php\n}<\/code><\/pre>\n\n<p>\u89e3\u91cb\u4e00\u4e0b\u4e0a\u9762\u9019\u6bb5\u4ee3\u78bc\uff1a<\/p>\n\n<p>\u9019\u6bb5\u4ee3\u78bc\u662f\u7528\u4f86\u70baWooCommerce\u8a02\u55ae\u7de8\u8f2f\u9801\u9762\u6dfb\u52a0\u201c\u8907\u88fd\u201d\u6309\u9215\uff0c\u4ee5\u4fbf\u5feb\u901f\u8907\u88fd\u8a02\u55ae\u4e2d\u7684\u96fb\u5b50\u90f5\u4ef6\u5730\u5740\u3001\u96fb\u8a71\u865f\u78bc\u3001\u5e33\u55ae\u4f4d\u5740\u548c\u914d\u9001\u4f4d\u5740\u3002<\/p>\n\n<p>\u4ee3\u78bc\u7684\u6838\u5fc3\u662f\u4f7f\u7528\u4e86WordPress\u7684\u9264\u5b50\uff08hook\uff09\u4f86\u5c07\u81ea\u5b9a\u7fa9\u51fd\u6578\u6dfb\u52a0\u5230\u7279\u5b9a\u7684\u4f4d\u7f6e\u3002 \u5177\u9ad4\u4f86\u8aaa\uff0c\u4ee3\u78bc\u4f7f\u7528\u4e86\u4ee5\u4e0b\u5169\u500b\u9264\u5b50\uff1a<\/p>\n\n<ul class=\"wp-block-list\">\n<li>woocommerce_admin_order_data_after_billing_address \u9264\u5b50\uff1a\u8a72\u9264\u5b50\u6703\u5728\u5e33\u55ae\u5730\u5740\u5f8c\u9762\u6dfb\u52a0\u4e00\u4e9b\u81ea\u5b9a\u7fa9\u5167\u5bb9\u3002<\/li>\n\n\n\n<li>woocommerce_admin_order_data_after_shipping_address \u9264\u5b50\uff1a\u8a72\u9264\u5b50\u6703\u5728\u914d\u9001\u5730\u5740\u5f8c\u9762\u6dfb\u52a0\u4e00\u4e9b\u81ea\u5b9a\u7fa9\u5167\u5bb9\u3002<\/li>\n<\/ul>\n\n<p>\u5c0d\u65bc\u96fb\u5b50\u90f5\u4ef6\u5730\u5740\u548c\u96fb\u8a71\u865f\u78bc\u7684\u201c\u8907\u88fd\u201d\u6309\u9215\uff0c\u4ee3\u78bc\u4f7f\u7528\u4e86WooCommerce\u8a02\u55ae\u7269\u4ef6\u7684get_billing_email\uff08\uff09\u548cget_billing_phone\uff08\uff09\u65b9\u6cd5\u4f86\u7372\u53d6\u8a02\u55ae\u7684\u96fb\u5b50\u90f5\u4ef6\u5730\u5740\u548c\u96fb\u8a71\u865f\u78bc\uff0c\u4e26\u4f7f\u7528\u4e86ClipboardJS\u5eab\u4f86\u5be6\u73fe\u8907\u88fd\u64cd\u4f5c\u3002<\/p>\n\n<p>\u5c0d\u65bc\u5e33\u55ae\u4f4d\u5740\u548c\u914d\u9001\u4f4d\u5740\u7684\u201c\u8907\u88fd\u201d\u6309\u9215\uff0c\u4ee3\u78bc\u4f7f\u7528\u4e86WooCommerce\u8a02\u55ae\u7269\u4ef6\u7684get_formatted_billing_address\uff08\uff09\u548cget_formatted_shipping_address\uff08\uff09\u65b9\u6cd5\u4f86\u7372\u53d6\u683c\u5f0f\u5316\u7684\u5e33\u55ae\u4f4d\u5740\u548c\u914d\u9001\u4f4d\u5740\uff0c\u7136\u5f8c\u4f7f\u7528PHP\u7684str_replace\uff08\uff09\u51fd\u6578\u5c07\u5730\u5740\u8cc7\u8a0a\u4e2d\u7684<br\/>\u6a19\u7c64\u66ff\u63db\u70ba\u9017\u865f\uff0c\u4e26\u4f7f\u7528ClipboardJS\u5eab\u4f86\u5be6\u73fe\u8907\u88fd\u64cd\u4f5c\u3002<\/p>\n\n<p>\u6700\u5f8c\uff0c\u70ba\u4e86\u78ba\u4fdd\u4ee3\u78bc\u5728WooCommerce\u8a02\u55ae\u7de8\u8f2f\u9801\u9762\u4e0a\u6b63\u5e38\u5de5\u4f5c\uff0c\u60a8\u9700\u8981\u5728\u8a02\u55ae\u7de8\u8f2f\u9801\u9762\u4e0a\u8f09\u5165jQuery\u548cClipboardJS\u5eab\u3002 \u2014\u2014\u53ea\u8981\u80fd\u8907\u88fd\u5c31\u884c\u4e86\uff0c\u9019\u908a\u53ea\u662f\u7d66\u6280\u8853\u4eba\u54e1\u770b\u7684\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6211\u6709\u4e00\u4f4dB2C\u8de8\u5883\u96fb\u5546\u96f6\u552e\u7ad9\u7684\u67b6\u8a2d\u7db2\u7ad9\u5ba2\u6236\uff0c\u5728\u904b\u71df\u6642\uff0c\u6709\u4e00\u500b\u5c0f\u9700\u6c42\uff1a\u5e0c\u671b\u80fd\u5728WooCommerce\u7684\u8a02\u55ae\u8a73\u60c5\u9801\u9762\u4e2d\uff0c\u80fd\u5920\u5c07Billing\uff08\u5e33\u55ae\u4f4d\u5740\uff09\u3001Shipping\uff08\u914d\u9001\u5730\u5740\uff09\u986f\u793a\u5728\u4e00\u884c\u4e2d\uff0c\u9019\u6a23\u65b9\u4fbf\u8907\u88fd\u5230\u81ea\u5df1\u7684ERP\u7cfb\u7d71\u4e2d\u9032\u884c\u7ba1\u7406\u3002 \u8003\u616e\u5230\u6700\u7d42\u76ee\u7684\u662f\u70ba\u4e86\u8907\u88fd\uff0c\u90a3\u9ebc\u6dfb\u52a0\u4e00\u9375\u8907\u88fd\u5e33\u55ae\u4f4d\u5740\u3001\u914d\u9001\u4f4d\u5740\u7684\u529f\u80fd\u5c31\u53ef\u4ee5\u4e86\uff0c\u9806\u5e36\u7d66\u90f5\u7bb1\u548c\u96fb\u8a71\u4e5f\u6dfb\u52a0\u4e00\u9375\u8907\u88fd\u7684\u529f\u80fd\u3002 \u65bc\u662f\uff0c\u4e0b\u5716\u4fbf\u662f\u6700\u7d42\u7684\u6548\u679c\u5566\uff0c\u5b83\u662f\u600e\u9ebc\u5be6\u73fe\u7684\u5462\uff1f  [&hellip;]<\/p>\n","protected":false},"featured_media":527192,"template":"","class_list":["post-528889","code-snippet","type-code-snippet","status-publish","has-post-thumbnail","hentry"],"acf":[],"taxonomy_info":[],"featured_image_src_large":["https:\/\/loyseo.com\/wp-content\/uploads\/2023\/04\/add-copy-to-woocommerce-edit-order-page-billing-shipping-address.png",2345,717,false],"author_info":[],"comment_info":"","_links":{"self":[{"href":"https:\/\/loyseo.com\/zh-hant\/wp-json\/wp\/v2\/code-snippet\/528889","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:featuredmedia":[{"embeddable":true,"href":"https:\/\/loyseo.com\/zh-hant\/wp-json\/wp\/v2\/media\/527192"}],"wp:attachment":[{"href":"https:\/\/loyseo.com\/zh-hant\/wp-json\/wp\/v2\/media?parent=528889"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}