{"id":232778,"date":"2023-01-28T09:53:00","date_gmt":"2023-01-28T06:53:00","guid":{"rendered":"https:\/\/wordpress.mediadoma.com\/?p=232778"},"modified":"2022-11-10T17:43:50","modified_gmt":"2022-11-10T14:43:50","slug":"kuinka-naeyttaeae-woocommercen-wordpressin-normaali-oletushinta-myyntihinnan-perusteella","status":"publish","type":"post","link":"https:\/\/wordpress.mediadoma.com\/fi\/kuinka-naeyttaeae-woocommercen-wordpressin-normaali-oletushinta-myyntihinnan-perusteella\/","title":{"rendered":"Kuinka n\u00e4ytt\u00e4\u00e4 Woocommercen\/WordPressin normaali oletushinta myyntihinnan perusteella?"},"content":{"rendered":"<p><a href=\"https:\/\/helloacm.com\/how-to-remove-product-review-in-woocommercewordpress\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">Woocommerce<\/a> on tehokas laajennus\/kehys, jonka avulla on mahdollista perustaa verkkokauppa WordPressill\u00e4. Voit muokata kunkin tuotteen attribuutteja, mutta joskus tuotteita on niin paljon, ett\u00e4 tuotteen tietyn m\u00e4\u00e4ritteen p\u00e4ivitt\u00e4minen voi vied\u00e4 aikaa.<\/p>\n<p>Jos esimerkiksi unohdit laittaa tavaroiden normaalihinnan, se ei n\u00e4yt\u00e4 normaalihintaa ristiinkirjasimilla, kuten ~100,00 GBP~. Mutta normaalihinta olisi hyv\u00e4 laittaa niin, ett\u00e4 asiakkaat kokevat tavaran olevan myynniss\u00e4 (halvemmalla) ja t\u00e4m\u00e4 varmasti nostaa ostoprosenttia.<\/p>\n<p>Voit kirjoittaa monimutkaisen SQL:n p\u00e4ivitt\u00e4\u00e4ksesi metatiedot, mutta se on riskialtista eik\u00e4 v\u00e4ltt\u00e4m\u00e4tt\u00e4 ole niin joustava kuin seuraava menetelm\u00e4. Laita seuraava PHP-koodi lapsiteeman mallipohjaan <strong>functions.php<\/strong><\/p>\n<pre><code>function helloacm_regular_price( $price, $product) {\n\u00a0 $price_factor = 1.3; \/\/ show sale price * 1.3 \n\u00a0 $sale_price = $product-&gt;get_sale_price(); \/\/ get sale price\n\u00a0 if (!is_numeric($sale_price)) { \/\/ sale price not set\n\u00a0 \u00a0 return $price; \u00a0\/\/ return default price.\n\u00a0 }\n\u00a0 $exp_price = $sale_price * $price_factor; \u00a0\/\/ get expected regular price\n\u00a0 if ($price &gt; 0) { \u00a0\/\/ if regular price is filled\n\u00a0 \u00a0 if ($price &lt; $sale_price) { \/\/ if it is even smaller than sale price\n\u00a0 \u00a0 \u00a0 return $exp_price; \u00a0\/\/ return corrected regular price\n\u00a0 \u00a0 } \u00a0 \u00a0 \n\u00a0 \u00a0 return $price; \/\/ otherwise return the input regular price\n\u00a0 }\n\u00a0 return $exp_price; \/\/ return the default regular price\n}\nadd_filter( 'woocommerce_get_regular_price', 'helloacm_regular_price', 10, 2);<\/code><\/pre>\n<p>Se on siin\u00e4. Jos normaalihintaa ei anneta, se n\u00e4ytt\u00e4\u00e4 oletusarvoisen normaalihinnan, joka on <strong>$price_factor<\/strong> kertaa myyntihinta. Muussa tapauksessa tehd\u00e4\u00e4n turvallisuustarkastus, jolla varmistetaan, ett\u00e4 normaalihinta on aina myyntihintaa korkeampi.<\/p>\n<p>T\u00e4m\u00e4 ei muuta tietokantaa, joten sit\u00e4 pidet\u00e4\u00e4n turvallisimpana tapana pelata temppuja. Suodatin <strong>woocommerce_get_regular_price<\/strong> lis\u00e4t\u00e4\u00e4n ennen normaalihinnan palauttamista.<\/p>\n<p><div id=\"PostUnique_PostSource\" style=\"padding-top: 50px\">:  <a target=\"_blank\" rel=\"noopener nofollow\" href=\"\/\/helloacm.com\" class=\"external external_icon\">helloacm.com<\/a><\/div><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Kuinka n\u00e4ytt\u00e4\u00e4 Woocommercen\/WordPressin normaali oletushinta myyntihinnan perusteella?<\/p>\n","protected":false},"author":1,"featured_media":223696,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_wp_rev_ctl_limit":""},"categories":[895,813,834,843,803,854,864],"tags":[1166],"class_list":["post-232778","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-koodi","category-laajennuksia","category-opas-aloittelijoille","category-opetusohjelmia","category-php-5","category-woocommerce-5","category-wordpress-5","tag-affiai-fi"],"_links":{"self":[{"href":"https:\/\/wordpress.mediadoma.com\/fi\/wp-json\/wp\/v2\/posts\/232778","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.mediadoma.com\/fi\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wordpress.mediadoma.com\/fi\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/fi\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/fi\/wp-json\/wp\/v2\/comments?post=232778"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.mediadoma.com\/fi\/wp-json\/wp\/v2\/posts\/232778\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/fi\/wp-json\/wp\/v2\/media\/223696"}],"wp:attachment":[{"href":"https:\/\/wordpress.mediadoma.com\/fi\/wp-json\/wp\/v2\/media?parent=232778"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/fi\/wp-json\/wp\/v2\/categories?post=232778"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/fi\/wp-json\/wp\/v2\/tags?post=232778"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}