{"id":6508,"date":"2021-11-21T11:20:00","date_gmt":"2021-11-21T11:20:00","guid":{"rendered":"https:\/\/musilda.cz\/?p=6508"},"modified":"2021-11-21T11:20:00","modified_gmt":"2021-11-21T11:20:00","slug":"jak-skryt-specificke-objednavky-pro-uzivatele-v-administraci","status":"publish","type":"post","link":"https:\/\/affinite.io\/cs\/jak-skryt-specificke-objednavky-pro-uzivatele-v-administraci\/","title":{"rendered":"Jak skr\u00fdt specifick\u00e9 objedn\u00e1vky pro u\u017eivatele v administraci"},"content":{"rendered":"\n

V p\u0159\u00edpad\u011b, \u017ee se v administraci e-shopu pohybuje v\u00edce lid\u00ed, mus\u00edte v n\u011b m\u00edt d\u016fv\u011bru, nebo jim omezovat to co vid\u00ed a mohou zobrazit. A do toho mohou pat\u0159it i specifick\u00e9 objedn\u00e1vky.<\/p>\n\n\n\n

Uva\u017eujme, \u017ee prod\u00e1v\u00e1me nap\u0159\u00edklad velmi specifick\u00e9 produkty, u nich\u017e je p\u0159\u00edprava vychyst\u00e1n\u00ed objedn\u00e1vky sv\u011b\u0159ena r\u016fzn\u00fdm lidem. Tak\u017ee u\u017eivatel A, se m\u00e1 v\u011bnovat objedn\u00e1vk\u00e1m, v kter\u00fdch je zbo\u017e\u00ed, kter\u00e9 m\u00e1 na starosti a ostatn\u00ed nepot\u0159ebuje vid\u011bt. <\/p>\n\n\n\n

Tento snippet jako takov\u00fd ne\u0159e\u0161\u00ed ozna\u010den\u00ed objedn\u00e1vky pro ur\u010dit\u00e9ho u\u017eivatele, proto\u017ee to je mimo r\u00e1mec tohoto \u010dl\u00e1nku. Pro p\u0159edstavu, p\u0159i vytvo\u0159en\u00ed objedn\u00e1vky si n\u011bkdo koup\u00ed vodn\u00ed sk\u016ftr a vy do datab\u00e1ze zap\u00ed\u0161ete custom field, kter\u00fd ozna\u010d\u00ed, \u017ee tuto objedn\u00e1vku vy\u0159izuje Karel. Ten by tak m\u011bl vid\u011bt jen sv\u00e9 objedn\u00e1vky.<\/p>\n\n\n\n

Pro testov\u00e1n\u00ed si tedy k objedn\u00e1vce p\u0159id\u00e1me specifick\u00e9 post meta:<\/p>\n\n\n\n

\"\"<\/a><\/figure>\n\n\n\n

Kdy\u017e se Karel p\u0159ihl\u00e1s\u00ed do administrace, vid\u00ed v\u0161echny objedn\u00e1vky:<\/p>\n\n\n\n

\"\"<\/a><\/figure>\n\n\n\n

Pro omezen\u00ed zobrazen\u00ed, pou\u017eijeme akci pre_get_posts:<\/p>\n\n\n\n

if ( is_admin() ) {\n\n\tadd_action('pre_get_posts', 'musilda_hide_orders' );\n\tfunction musilda_hide_orders( $query ) {\n\n\t\t$current_screen = get_current_screen();\n\n\t\tif ( 'edit-shop_order' == $current_screen->id ) {\n\n\t\t\t$user_id = get_current_user_id();\n\n\t\t\tif ( 1 == $user_id ) {\n\n\t\t\t\t$meta_query = $query->get( 'meta_query' );\n\t\t\t\tif ( is_array( $meta_query ) ) {\n\t\t\t\t\t$meta_query[] = array(\n\t\t\t\t\t\t'key'    =>'user_name',\n\t\t\t\t\t\t'value'  =>'Karel',\n\t\t\t\t\t\t'compare'=>'='\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\t$meta_query = array(\n\t\t\t\t\t\tarray(\n\t\t\t\t\t\t\t'key'    =>'user_name',\n\t\t\t\t\t\t\t'value'  =>'Karel',\n\t\t\t\t\t\t\t'compare'=>'='\n\t\t\t\t\t\t)\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\t$query->set( 'meta_query', $meta_query );\n\n\t\t\t}\n\n\t\t}\n\n\t\treturn $query;\n\n\t}\n\n}<\/code><\/pre>\n\n\n\n

Nejprve si ov\u011b\u0159\u00edm, \u017ee jde o adminsitraci, pak si ov\u011b\u0159\u00edme, zda se nach\u00e1z\u00edme na v\u00fdpisu objedn\u00e1vek, ov\u011b\u0159\u00edme, \u017ee jde o spr\u00e1vn\u00e9ho u\u017eivatele a pak uprav\u00edme meta query. <\/p>\n\n\n\n

Podm\u00ednky p\u0159i \u00faprav\u011b meta query je nezbytn\u00e1, proto\u017ee meta query ji\u017e m\u016f\u017ee existovat a pak jej roz\u0161i\u0159ujete. <\/p>\n\n\n\n

V\u00fdsledek:<\/p>\n\n\n\n

\"\"<\/a><\/figure>\n\n\n\n

A Karel vid\u00ed jen jednu (svoji) objedn\u00e1vku. <\/p>\n\n\n\n

Mimochodem, takto zjednodu\u0161en\u011b funguj\u00ed multi vendor pluginy. <\/p>\n","protected":false},"excerpt":{"rendered":"

V p\u0159\u00edpad\u011b, \u017ee se v administraci e-shopu pohybuje v\u00edce lid\u00ed, mus\u00edte v n\u011b m\u00edt d\u016fv\u011bru, nebo jim omezovat to co vid\u00ed a mohou zobrazit. A do toho mohou pat\u0159it i specifick\u00e9 objedn\u00e1vky. Uva\u017eujme, \u017ee prod\u00e1v\u00e1me nap\u0159\u00edklad velmi specifick\u00e9 produkty, u nich\u017e je p\u0159\u00edprava vychyst\u00e1n\u00ed objedn\u00e1vky sv\u011b\u0159ena r\u016fzn\u00fdm lidem. Tak\u017ee u\u017eivatel A, se m\u00e1 v\u011bnovat objedn\u00e1vk\u00e1m,<\/p>\n","protected":false},"author":1,"featured_media":5600,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29],"tags":[],"class_list":["post-6508","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-woocommerce-snippety"],"_links":{"self":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/6508"}],"collection":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/comments?post=6508"}],"version-history":[{"count":0,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/6508\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/media\/5600"}],"wp:attachment":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/media?parent=6508"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/categories?post=6508"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/tags?post=6508"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}