{"id":6411,"date":"2021-10-24T06:52:00","date_gmt":"2021-10-24T06:52:00","guid":{"rendered":"https:\/\/musilda.cz\/?p=6411"},"modified":"2021-10-24T06:52:00","modified_gmt":"2021-10-24T06:52:00","slug":"jak-zobrazit-hodnotu-nakupu-pro-ziskani-slevy","status":"publish","type":"post","link":"https:\/\/affinite.io\/cs\/jak-zobrazit-hodnotu-nakupu-pro-ziskani-slevy\/","title":{"rendered":"Jak zobrazit hodnotu n\u00e1kupu pro z\u00edsk\u00e1n\u00ed slevy"},"content":{"rendered":"\n

V minul\u00e9m \u010dl\u00e1nku jsme si uk\u00e1zali, jak jednodu\u0161e p\u0159idat slevu pro z\u00e1kazn\u00edka, pokud nakoup\u00ed za ur\u010ditou \u010d\u00e1stku. <\/p>\n\n\n\n

Dnes mu uk\u00e1\u017eeme, za kolik mus\u00ed je\u0161t\u011b nakoupit, aby slevu z\u00edskal.<\/p>\n\n\n\n

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

V tomto snippetu<\/a> jsme si zobrazili notifikaci v ko\u0161\u00edku, ale nejsem si jist, zda je to zcela vhodn\u00e9, proto si vytvo\u0159\u00edme vlastn\u00ed div, kter\u00fd nastylujeme a budeme ho zobrazovat na v\u0161ech WooCommerce str\u00e1nk\u00e1ch.<\/p>\n\n\n\n

Pou\u017eijeme hook woocommerce_before_main_content a funkci zav\u011bs\u00edme na pozici 15, a\u0165 se tref\u00edme p\u0159ed WooCommerce breadcrumbs, ale za otev\u00edrac\u00ed div. <\/p>\n\n\n\n

add_action( 'woocommerce_before_main_content', 'display_order_discount_rule', 15 );\nfunction display_order_discount_rule() {\n\n\tif ( function_exists( 'WC' ) ) {\n\t\tif ( is_woocommerce() ) {\n\n\t\t\t$total = WC()->cart->get_cart_contents_total() + WC()->cart->get_cart_contents_tax(); \/\/hodnota s dan\u00ed\n\t\t\t$total = WC()->cart->get_cart_contents_total(); \/\/hodnota bez dan\u011b\n\n\t\t\tif ( $total < 20 ) {\n\t\t\t\t$result = 20 - $total;\n\n\t\t\t\techo '<div class=\"order-dicount-notice\">';\n\t\t\t\t\techo sprintf( __( 'Nakupte je\u0161t\u011b za %1$s a z\u00edsk\u00e1te slevu 10 %%', 'musilda' ), wc_price( $result ) );\n\t\t\t\techo '<\/div>';\n\n\t\t\t}\n\n\n\t\t}\n\t}\n}\n<\/code><\/pre>\n\n\n\n

A tro\u0161ku si to nastylujeme:<\/p>\n\n\n\n

.order-dicount-notice{\n\twidth:100%;\n\tfont-size:20px;\n\ttext-align:center;\n\tpadding:20px;\n\tborder:solid 1px #eeeeee;\n\tbackground: rgb(255,255,255);\n\tbackground: linear-gradient(180deg, rgba(255,255,255,1) 0%, rgba(255,255,255,1) 0%, rgba(238,238,238,1) 100%, rgba(238,238,238,1) 100%);\n}<\/code><\/pre>\n\n\n\n

V\u00fdsledek pak uvid\u00edme na ka\u017ed\u00e9 WooCommerce str\u00e1nce<\/h2>\n\n\n\n
\"\"<\/a><\/figure>\n\n\n\n

O tom, jak vytvo\u0159it slevu jsem psal zde https:\/\/musilda.cz\/sleva-z-objednavky-podle-hodnoty-kosiku\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"

V minul\u00e9m \u010dl\u00e1nku jsme si uk\u00e1zali, jak jednodu\u0161e p\u0159idat slevu pro z\u00e1kazn\u00edka, pokud nakoup\u00ed za ur\u010ditou \u010d\u00e1stku. Dnes mu uk\u00e1\u017eeme, za kolik mus\u00ed je\u0161t\u011b nakoupit, aby slevu z\u00edskal. V tomto snippetu jsme si zobrazili notifikaci v ko\u0161\u00edku, ale nejsem si jist, zda je to zcela vhodn\u00e9, proto si vytvo\u0159\u00edme vlastn\u00ed div, kter\u00fd nastylujeme a budeme<\/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-6411","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\/6411"}],"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=6411"}],"version-history":[{"count":0,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/posts\/6411\/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=6411"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/categories?post=6411"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/affinite.io\/cs\/wp-json\/wp\/v2\/tags?post=6411"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}