{"id":2646,"date":"2015-12-14T05:54:18","date_gmt":"2015-12-14T05:54:18","guid":{"rendered":"http:\/\/musilda.cz\/?p=2646"},"modified":"2015-12-14T05:54:18","modified_gmt":"2015-12-14T05:54:18","slug":"jak-zobrazit-sazbu-dane-produktu-ve-woocommerce","status":"publish","type":"post","link":"https:\/\/affinite.io\/cs\/jak-zobrazit-sazbu-dane-produktu-ve-woocommerce\/","title":{"rendered":"Jak zobrazit sazbu dan\u011b produktu ve WooCommerce"},"content":{"rendered":"
P\u0159i zobrazen\u00ed produktu ve WooCommerce, je pom\u011brn\u011b jednoduch\u00e9 zobrazit v\u00fd\u0161i DPH z ceny produktu. V\u011bt\u0161\u00ed probl\u00e9m, je ale zobrazit sazbu dan\u011b, pro konkr\u00e9tn\u00ed produkt.<\/p>\n
P\u016fvodn\u011b tento dotaz zazn\u011bl na Facebooku, kde jsem na n\u011bj odpov\u011bd\u011bl. Autor dotazu v\u0161ak nijak nereagoval a proto\u017ee jsem zrovna tento t\u00fdden, pot\u0159eboval \u0159e\u0161it podobn\u00fd probl\u00e9m, v tomto \u010dl\u00e1nku si uk\u00e1\u017eeme jednoduch\u00fd snippet, kter\u00fd sazbu zobraz\u00ed.<\/p>\n
Nebudu zde zapisovat \u017e\u00e1dnou funkci, script si vlo\u017ete do vlastn\u00ed funkce a vyu\u017eijte takov\u00fd hook, jak\u00fd pot\u0159ebujete.<\/p>\n
Jedin\u00e9, co budete pot\u0159ebovat, je id produktu. Proto\u017ee je produkt custom post type, m\u016f\u017eete pou\u017e\u00edt i „global $post;“.<\/p>\n
$_product = new WC_Product($post->ID);\n$tax_rates = WC_Tax::get_rates( $_product->get_tax_class() );\n if(!empty($tax_rates)){\n foreach($tax_rates as $tax ){\n $dph = $tax['rate'];\n $nazev = $tax['label'];\n }\n }\n<\/pre>\nV prom\u011bnn\u00e9 $dph je sazba dan\u011b, v $nazev je jej\u00ed jm\u00e9no.<\/p>\n
A\u0165 slou\u017e\u00ed.<\/p>\n\n\n