{"id":538,"date":"2022-06-14T13:07:58","date_gmt":"2022-06-14T11:07:58","guid":{"rendered":"https:\/\/www.areaweb.sk\/?p=538"},"modified":"2022-06-14T13:11:16","modified_gmt":"2022-06-14T11:11:16","slug":"pridanie-stlpca-v-zozname-objednavok","status":"publish","type":"post","link":"https:\/\/www.areaweb.sk\/cs\/pridanie-stlpca-v-zozname-objednavok\/","title":{"rendered":"Pridanie st\u013apca v zozname objedn\u00e1vok"},"content":{"rendered":"<p class=\"wp-block-paragraph\">Pridanie st\u013apca s n\u00e1zvom sp\u00f4sob dopravy<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ add columns sposob dopravy\nfunction add_shipping_to_orders_table($columns) {\n    $columns&#91;'shipping_method'] = 'Sp\u00f4sob dopravy';\n    return $columns;\n}\nadd_filter( 'manage_edit-shop_order_columns', 'add_shipping_to_orders_table', 11 );<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Nastavenie hodnoty st\u013apca<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function get_shipping_columns_values($column) {\n    global $post;\n    \n    \/\/ z&iacute;skame n&aacute;zov sp&ocirc;sob dopravy\n    $order_facory = new WC_Order_Factory();\n    $order = $order_facory-&gt;get_order( $post-&gt;ID );\n\n    if ( $column == &#039;shipping_method&#039; ) {   \n        if ($order-&gt;get_shipping_method() == &#039;Zv&yacute;raznen&yacute; stav&#039;) {\n            echo &#039;&lt;strong style=&quot;color:red&quot;&gt;Vlastn&yacute; n&aacute;zov&lt;strong&gt;&#039;;\n        }\n        else{\n            echo $order-&gt;get_shipping_method();\n        }\n    }\n\n\n}\n\nadd_action( &#039;manage_shop_order_posts_custom_column&#039;, &#039;get_shipping_columns_values&#039;, 2 );<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Pridanie zoradenia pod\u013ea st\u013apca<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function customize_sort_function_custom_values( $columns ) {\n\tglobal $wpdb;\n\n    $custom = array(\n        'shipping_method' =&gt; 'shipping_method'\n    );\n\n    return wp_parse_args( $custom, $columns );\n}\n\nadd_filter( \"manage_edit-shop_order_sortable_columns\", 'customize_sort_function_custom_values' );\n\n\n\nfunction order_by_shipping_method_order_join($query) {\n    global $wpdb;\n\n    if ( is_admin() &amp;&amp; $_GET&#91;'post_type'] === 'shop_order' &amp;&amp; $_GET&#91;'orderby'] === 'shipping_method' ) {\n    \t$first_item_in_order = \"SELECT order_item_id FROM {$wpdb-&gt;prefix}woocommerce_order_items WHERE order_id = $wpdb-&gt;posts.ID AND order_item_type = 'shipping' LIMIT 0, 1\";\n        $query .= \"LEFT JOIN {$wpdb-&gt;prefix}woocommerce_order_items AS items ON $wpdb-&gt;posts.ID = items.order_id AND items.order_item_id = ($first_item_in_order) \";\n        $query .= \"LEFT JOIN {$wpdb-&gt;prefix}woocommerce_order_itemmeta AS itemmeta ON items.order_item_id = itemmeta.order_item_id AND (itemmeta.meta_key = 'method_id') \";\n    }\n\n    return $query;\n}\n\nadd_filter('posts_join', 'order_by_shipping_method_order_join');<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Doplnenie funkcie v pr\u00edpade zl\u00e9ho filtrovania<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\nfunction order_by_shipping_method_where($where) {\n\tglobal $wpdb;\n\n\tif( is_admin() &amp;&amp; $_GET&#91;'post_type'] === 'shop_order' &amp;&amp; $_GET&#91;'orderby'] === 'shipping_method' ) {\n\t\tif(strpos($where, 'shop_webhook')) {\n\t\t\treturn \" AND $wpdb-&gt;posts.post_type = 'shop_order' AND itemmeta.meta_key = 'method_id'\";\n\t\t}\n\t}\n\n\treturn $where;\n}\n\nadd_filter('posts_where', 'order_by_shipping_method_where');\n\n\nfunction generate_replace_part($shipping_methods, $replace) {\n\t$key = array_shift(array_keys($shipping_methods));\n\t$value = array_shift($shipping_methods);\n\n\t$query_part = \"REPLACE($replace, '$key', '$value')\";\n\n\tif(!empty($shipping_methods)) {\n\t\treturn generate_replace_part($shipping_methods, $query_part);\n\t}\n\n\treturn $query_part;\n}\n\nfunction order_by_shipping_method_order($order_by) {\n\tglobal $wpdb;\n\n\t$shipping_methods = array(\n\t\t'local_delivery' =&gt; 'Doru\u010denie kurierom',\n\t\t'local_pickup'   =&gt; 'Osobn\u00fd odber',\n\t\t'pick_pack_pont' =&gt; 'Pick Pack Pont'\n\t);\n\n\tif( is_admin() &amp;&amp; $_GET&#91;'post_type'] === 'shop_order' &amp;&amp; $_GET&#91;'orderby'] === 'shipping_method' ) {\n\t\treturn generate_replace_part($shipping_methods, 'itemmeta.meta_value') . \" \" . strtoupper($_GET&#91;'order']);\n\t}\n\t\n\treturn $order_by;\n}\n\nadd_filter('posts_orderby', 'order_by_shipping_method_order');<\/code><\/pre>","protected":false},"excerpt":{"rendered":"<p>Pridanie st\u013apca s n\u00e1zvom sp\u00f4sob dopravy \/\/ add columns sposob dopravy function add_shipping_to_orders_table($columns) { $columns[&#8216;shipping_method&#8217;] = &#8216;Sp\u00f4sob dopravy&#8217;; return $columns; } add_filter(\u2026<\/p>\n","protected":false},"author":1,"featured_media":470,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[26],"tags":[],"class_list":["post-538","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-woocomerce"],"blocksy_meta":[],"acf":[],"_links":{"self":[{"href":"https:\/\/www.areaweb.sk\/cs\/wp-json\/wp\/v2\/posts\/538","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.areaweb.sk\/cs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.areaweb.sk\/cs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.areaweb.sk\/cs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.areaweb.sk\/cs\/wp-json\/wp\/v2\/comments?post=538"}],"version-history":[{"count":0,"href":"https:\/\/www.areaweb.sk\/cs\/wp-json\/wp\/v2\/posts\/538\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.areaweb.sk\/cs\/wp-json\/wp\/v2\/media\/470"}],"wp:attachment":[{"href":"https:\/\/www.areaweb.sk\/cs\/wp-json\/wp\/v2\/media?parent=538"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.areaweb.sk\/cs\/wp-json\/wp\/v2\/categories?post=538"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.areaweb.sk\/cs\/wp-json\/wp\/v2\/tags?post=538"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}