{"id":2213,"date":"2024-07-04T20:23:08","date_gmt":"2024-07-04T12:23:08","guid":{"rendered":"https:\/\/qishiya.com\/?p=2213"},"modified":"2024-07-04T20:23:09","modified_gmt":"2024-07-04T12:23:09","slug":"%e6%80%8e%e4%b9%88%e6%a0%b7%e8%a7%a3%e5%86%b3-woocommerce-%e4%b8%ad%e5%9b%be%e7%89%87%e5%af%bc%e5%85%a5%e8%b6%85%e6%97%b6","status":"publish","type":"post","link":"https:\/\/qishiya.com\/?p=2213","title":{"rendered":"\u600e\u4e48\u6837\u89e3\u51b3 woocommerce \u4e2d\u56fe\u7247\u5bfc\u5165\u8d85\u65f6"},"content":{"rendered":"\n<p>\u5728\u7528 woocommerce \u6279\u91cf\u5bfc\u5165\u56fe\u7247\u65f6\uff0c\u56e0\u4e3a\u5bfc\u5165\u7684\u5546\u54c1\u591a\u65f6\uff0c\u4f1a\u5bfc\u81f4\u56fe\u7247\u5bfc\u5165\u5931\u8d25\uff0c\u6211\u5728\u56fe\u7247\u5bfc\u5165\u5931\u8d25\u65f6\uff0c\u52a0\u4e86\u4e00\u4e2a\u4e0b\u8f7d\u7684 retry\uff0c\u56fe\u7247\u5bfc\u5165\u5931\u8d25\u7684\u6b21\u6570\u5927\u5927\u51cf\u5c11\uff0c\u4f46\u662f\u8fd9\u53ea\u662f\u4e00\u4e2a\u51cf\u5c11\uff0c\u5e76\u4e0d\u80fd\u5b8c\u5168\u675c\u7edd\uff0c\u4f46\u662f\u8fd9\u4e2a\u65b9\u6cd5\u662f\u6210\u672c\u6700\u8f7b\u7684\uff0c\u5176\u5b83\u7684\u65b9\u6cd5\u6211\u4f1a\u6301\u7eed\u5c1d\u8bd5\u3002<\/p>\n\n\n\n<p>\u6211\u5728\u4e0a\u4e00\u4e2a\u6587\u7ae0\u5173\u4e8e<a href=\"https:\/\/qishiya.com\/?p=2211\" data-type=\"post\" data-id=\"2211\">woocommerce \u5bfc\u5165\u903b\u8f91<\/a>\u6709\u8be6\u7ec6\u7684\u4ecb\u7ecd\uff0c\u6211\u5728\u8fd9\u4e2a\u4ee3\u7801\u91cc\u52a0\u4e86\u4e00\u4e2a retry \u7684\u903b\u8f91\uff0c\u4ee3\u7801\u5982\u4e0b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>     \/\/ Upload if attachment does not exists.\n                if ( ! $id &amp;&amp; stristr( $url, ':\/\/' ) ) {\n                        $attempt = 1;\n                        $retry_interval = 1; \/\/ Initial retry interval in seconds.\n\n                        while ($attempt &lt;= 3) {\n                                $upload = wc_rest_upload_image_from_url( $url );\n\n                                if ( ! is_wp_error( $upload ) ) {\n                                        $id = wc_rest_set_uploaded_image_as_attachment( $upload, $product_id );\n\n                                        if ( ! wp_attachment_is_image( $id ) ) {\n                                                \/* translators: %s: image URL *\/\n                                                throw new Exception( sprintf( __( 'Not able to attach \"%s\".', 'woocommerce' ), $url ), 400 );\n                                        }\n\n                                        \/\/ Save attachment source for future reference.\n                                        update_post_meta( $id, '_wc_attachment_source', $url );\n                                        break;\n                                } else {\n                                        if ($attempt === 3) {\n                                                throw new Exception( $upload->get_error_message(), 400 );\n                                        }\n                                        sleep($retry_interval);\n                                        $retry_interval *= 2; \/\/ Exponential backoff strategy.\n                                        $attempt++;\n                                }\n                        }\n                }<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u7528 woocommerce \u6279\u91cf\u5bfc\u5165\u56fe\u7247\u65f6\uff0c\u56e0\u4e3a\u5bfc\u5165\u7684\u5546\u54c1\u591a\u65f6\uff0c\u4f1a\u5bfc\u81f4\u56fe\u7247\u5bfc\u5165\u5931\u8d25\uff0c\u6211\u5728\u56fe\u7247\u5bfc\u5165\u5931\u8d25\u65f6\uff0c\u52a0\u4e86\u4e00\u4e2a\u4e0b\u8f7d\u7684 retry\uff0c\u56fe\u7247\u5bfc\u5165\u5931\u8d25\u7684\u6b21\u6570\u5927\u5927\u51cf\u5c11\uff0c\u4f46\u662f\u8fd9\u53ea\u662f\u4e00\u4e2a\u51cf\u5c11\uff0c\u5e76\u4e0d\u80fd\u5b8c\u5168\u675c\u7edd\uff0c\u4f46\u662f\u8fd9\u4e2a\u65b9\u6cd5\u662f\u6210\u672c\u6700\u8f7b\u7684\uff0c\u5176\u5b83\u7684\u65b9\u6cd5\u6211\u4f1a\u6301 &#8230; <a title=\"\u600e\u4e48\u6837\u89e3\u51b3 woocommerce \u4e2d\u56fe\u7247\u5bfc\u5165\u8d85\u65f6\" class=\"read-more\" href=\"https:\/\/qishiya.com\/?p=2213\" aria-label=\"\u66f4\u591a \u600e\u4e48\u6837\u89e3\u51b3 woocommerce \u4e2d\u56fe\u7247\u5bfc\u5165\u8d85\u65f6\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[639,597],"tags":[],"class_list":["post-2213","post","type-post","status-publish","format-standard","hentry","category-woocommerece","category-wordpress"],"_links":{"self":[{"href":"https:\/\/qishiya.com\/index.php?rest_route=\/wp\/v2\/posts\/2213","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/qishiya.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qishiya.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qishiya.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/qishiya.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2213"}],"version-history":[{"count":1,"href":"https:\/\/qishiya.com\/index.php?rest_route=\/wp\/v2\/posts\/2213\/revisions"}],"predecessor-version":[{"id":2214,"href":"https:\/\/qishiya.com\/index.php?rest_route=\/wp\/v2\/posts\/2213\/revisions\/2214"}],"wp:attachment":[{"href":"https:\/\/qishiya.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2213"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qishiya.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2213"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qishiya.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2213"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}