{"id":2424,"date":"2015-05-25T10:07:28","date_gmt":"2015-05-25T10:07:28","guid":{"rendered":"http:\/\/musilda.cz\/?p=2424"},"modified":"2015-05-25T10:07:28","modified_gmt":"2015-05-25T10:07:28","slug":"cena-produktu-pri-zmene-meny-ve-wpml","status":"publish","type":"post","link":"https:\/\/affinite.io\/cs\/cena-produktu-pri-zmene-meny-ve-wpml\/","title":{"rendered":"Cena produktu p\u0159i zm\u011bn\u011b m\u011bny ve WPML"},"content":{"rendered":"

Dne\u0161n\u00ed snippet je zde p\u0159edev\u0161\u00edm proto, abych jej na\u0161el, a\u017e jej budu n\u011bkdy pot\u0159ebovat. Co\u017e asi nebude tak \u010dasto.<\/p>\n

Snippet \u0159e\u0161\u00ed z\u00edsk\u00e1n\u00ed aktu\u00e1ln\u00ed ceny produktu ve WooCommerce, pokud m\u00e1te na eshopu v\u00edce m\u011bn a pou\u017e\u00edv\u00e1te WPML a jejich WooComerce Multilingual.<\/p>\n

Nejprve mus\u00edme z\u00edskat cenu produktu a k tomu vyu\u017eijeme get_price, metodu abstraktn\u00ed t\u0159\u00eddy WC_Product. J\u00e1 ve snippetu nem\u00e1m k dispozici objekt produktu, tak\u017ee jej mus\u00edm vytv\u00e1\u0159et, ale pokud jej vy m\u00e1te, tak jej znovu nevytv\u00e1\u0159ejte.<\/p>\n

\n$product = new WC_Product($product_id);\n$price = $product->get_price();\n<\/pre>\n

To je pom\u011brn\u011b jednoduch\u00e1 v\u011bc a i z\u00edsk\u00e1n\u00ed ceny dle aktu\u00e1ln\u00ed m\u011bny je jednoduch\u00e9, jen se to \u0161patn\u011b hled\u00e1. WPML m\u00e1 toti\u017e filter „wcml_raw_price_amount“, kter\u00fd to za v\u00e1s obstar\u00e1.<\/p>\n

\n$current_price = apply_filters( 'wcml_raw_price_amount', $price );\n<\/pre>\n

Cena, kterou dostanete, je v\u0161ak v \u010d\u00edseln\u00e9m form\u00e1tu, co\u017e m\u011b v tomto p\u0159\u00edpad\u011b vyhovovalo. Pokud by jste ji cht\u011bli vypsat na webu, museli by jste ji je\u0161t\u011b p\u0159eform\u00e1tovat, o co\u017e se postar\u00e1 funkce wc_price()<\/p>\n

\necho wc_price($current_price);\n<\/pre>\n

A to\u0165 v\u0161e. <\/p>\n","protected":false},"excerpt":{"rendered":"

Dne\u0161n\u00ed snippet je zde p\u0159edev\u0161\u00edm proto, abych jej na\u0161el, a\u017e jej budu n\u011bkdy pot\u0159ebovat. Co\u017e asi nebude tak \u010dasto. Snippet \u0159e\u0161\u00ed z\u00edsk\u00e1n\u00ed aktu\u00e1ln\u00ed ceny produktu ve WooCommerce, pokud m\u00e1te na eshopu v\u00edce m\u011bn a pou\u017e\u00edv\u00e1te WPML a jejich WooComerce Multilingual. Nejprve mus\u00edme z\u00edskat cenu produktu a k tomu vyu\u017eijeme get_price, metodu abstraktn\u00ed t\u0159\u00eddy WC_Product. J\u00e1<\/p>\n","protected":false},"author":1,"featured_media":2425,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19,25],"tags":[],"class_list":["post-2424","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-snippety","category-woocommerce"],"_links":{"self":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/2424"}],"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=2424"}],"version-history":[{"count":0,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/2424\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/media\/2425"}],"wp:attachment":[{"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/media?parent=2424"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/categories?post=2424"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/tags?post=2424"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}