{"id":5628,"date":"2020-06-05T15:57:36","date_gmt":"2020-06-05T15:57:36","guid":{"rendered":"https:\/\/musilda.cz\/?p=5628"},"modified":"2020-06-05T15:57:36","modified_gmt":"2020-06-05T15:57:36","slug":"jak-pridat-sloupec-do-administrace-objednavek-a-udelat-jej-raditelnym","status":"publish","type":"post","link":"https:\/\/affinite.io\/cs\/jak-pridat-sloupec-do-administrace-objednavek-a-udelat-jej-raditelnym\/","title":{"rendered":"Jak p\u0159idat sloupec do administrace objedn\u00e1vek a ud\u011blat jej \u0159aditeln\u00fdm"},"content":{"rendered":"\n

Pot\u0159ebujete ve v\u00fdpisu objedn\u00e1vek zobrazit sloupec s vlastn\u00edmi \u00fadaji a je\u0161t\u011b m\u00edt mo\u017enost je \u0159adit? Uk\u00e1\u017ei v\u00e1m jak na to.<\/p>\n\n\n\n

Budeme muset u\u010dinit t\u0159i kroky:<\/h2>\n\n\n\n
  1. vytvo\u0159en\u00ed vlastn\u00edho sloupce<\/li>
  2. zobrazen\u00ed hodnoty v sloupci<\/li>
  3. umo\u017enit \u0159azen\u00ed podle hodnoty<\/li><\/ol>\n\n\n\n

    Vytvo\u0159en\u00ed vlastn\u00edho sloupce<\/h2>\n\n\n\n

    Pou\u017eijeme dynamick\u00fd hook manage_{post-type}_posts_columns, kter\u00fd umo\u017e\u0148uje p\u0159idat do jak\u00e9koliv tabulky v\u00fdpisu v administraci nov\u00fd sloupec. <\/p>\n\n\n\n

    Ve filtru p\u0159istoup\u00edme k poli z\u00e1znam\u016f a pomoc\u00ed foreach najdeme pole s id „name“ a za n\u011bj d\u00e1me sv\u00e9 vlastn\u00ed – hmotnost objedn\u00e1vky.<\/p>\n\n\n\n\n\n\n\n

    Zobrazen\u00ed hodnoty ve sloupci<\/h2>\n\n\n\n

    Proto\u017ee sloupec bez hodnoty je k ni\u010demu. A proto\u017ee celkovou hmotnost objedn\u00e1vky m\u00e1me ulo\u017eenou v post meta ( Jak z\u00edskat celkovou hmotnost objedn\u00e1vky ve WooCommerce<\/a> ), tak si jen vyp\u00ed\u0161eme hodnotu toho pole.<\/p>\n\n\n\n

    Op\u011bt pou\u017eijeme dynamick\u00fd hook a pokud se jedn\u00e1 o sloupce, kter\u00fd jsme definovali, tak vyp\u00ed\u0161eme hodnotu custom fieldu.<\/p>\n\n\n\n\n\n\n\n

    \u0158azen\u00ed podle hodnoty<\/h2>\n\n\n\n

    Nyn\u00ed mus\u00edme ud\u011blat dv\u011b v\u011bci. Prvn\u00ed je, \u017ee mus\u00edme zaregistrovat column jako sortable. D\u00edky tomu na n\u011bj budete moci kliknout a objedn\u00e1vky se podle n\u011bj se\u0159ad\u00ed. <\/p>\n\n\n\n

    Druh\u00e1 je, budeme muset upravit $query, aby se objedn\u00e1vky skute\u010dn\u011b \u0159adily podle hmotnosti. To ud\u011bl\u00e1me pomoc\u00ed pre_get_posts filtru, kter\u00fd $query umo\u017e\u0148uje m\u011bnit. Mus\u00edme v\u0161ak zkontrolovat, zda jsme opravdu v adminu.<\/p>\n\n\n\n\n\n\n\n

    No a to je v\u0161e. Nyn\u00ed m\u00e1te v administraci nov\u00fd sloupec s hmotnost\u00ed, kter\u00fd m\u016f\u017eete pou\u017e\u00edt pro se\u0159azen\u00ed objedn\u00e1vek. <\/p>\n\n\n\n

    Dal\u0161\u00ed u\u017eite\u010dn\u00e9 snippety najdete na str\u00e1nce U\u017eite\u010dn\u00e9 snippety pro WooCommerce<\/a><\/strong> <\/p>\n","protected":false},"excerpt":{"rendered":"

    Pot\u0159ebujete ve v\u00fdpisu objedn\u00e1vek zobrazit sloupec s vlastn\u00edmi \u00fadaji a je\u0161t\u011b m\u00edt mo\u017enost je \u0159adit? Uk\u00e1\u017ei v\u00e1m jak na to. Budeme muset u\u010dinit t\u0159i kroky: vytvo\u0159en\u00ed vlastn\u00edho sloupce zobrazen\u00ed hodnoty v sloupci umo\u017enit \u0159azen\u00ed podle hodnoty Vytvo\u0159en\u00ed vlastn\u00edho sloupce Pou\u017eijeme dynamick\u00fd hook manage_{post-type}_posts_columns, kter\u00fd umo\u017e\u0148uje p\u0159idat do jak\u00e9koliv tabulky v\u00fdpisu v administraci nov\u00fd sloupec. Ve<\/p>\n","protected":false},"author":1,"featured_media":5600,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19,25,29],"tags":[],"class_list":["post-5628","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-snippety","category-woocommerce","category-woocommerce-snippety"],"_links":{"self":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/5628"}],"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=5628"}],"version-history":[{"count":0,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/5628\/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=5628"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/categories?post=5628"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/tags?post=5628"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}