{"id":233350,"date":"2023-02-12T14:39:00","date_gmt":"2023-02-12T11:39:00","guid":{"rendered":"https:\/\/wordpress.mediadoma.com\/?p=233350"},"modified":"2022-11-10T20:36:53","modified_gmt":"2022-11-10T17:36:53","slug":"kuinka-muuttaa-yleisiae-woocommerce-tekstejae-koodilla","status":"publish","type":"post","link":"https:\/\/wordpress.mediadoma.com\/fi\/kuinka-muuttaa-yleisiae-woocommerce-tekstejae-koodilla\/","title":{"rendered":"Kuinka muuttaa yleisi\u00e4 WooCommerce-tekstej\u00e4 koodilla"},"content":{"rendered":"\n<p>WooCommerce on t\u00e4ynn\u00e4 suodattimia, koukkuja ja toimintoja, jotka auttavat sinua mukauttamaan ja hy\u00f6dynt\u00e4m\u00e4\u00e4n laajennusta teemassasi tai laajennuksessasi. T\u00e4ss\u00e4 on joitain pieni\u00e4, mutta hy\u00f6dyllisi\u00e4 koodiesimerkkej\u00e4, a-ha:ita ja ohjeita eri tekstitulosteiden yleisist\u00e4 muutoksista.<\/p>\n<h2>&quot;Lis\u00e4\u00e4 ostoskoriin&quot; -painikkeen tekstien muuttaminen<\/h2>\n<p>Suodattimia on kaksi; yksi &quot;lis\u00e4\u00e4 ostoskoriin&quot; -teksteille silmukassa (<code>woocommerce_product_add_to_cart_text<\/code>) ja toinen yksitt\u00e4isen tuotteen painikkeelle (<code>woocommerce_product_single_add_to_cart_text<\/code>):<\/p>\n<pre><code>\/\/ Single product view\nadd_filter('woocommerce_product_single_add_to_cart_text', function($text) {\n    return __('Buy this now', 'txtdomain');\n});\n\u00a0\n\/\/ Loop\nadd_filter('woocommerce_product_add_to_cart_text', function($text) {\n    return __('Buy this', 'txtdomain');\n});<\/code><\/pre>\n<p>Muista kuitenkin, ett\u00e4 t\u00e4m\u00e4 ohittaa kaikki &quot;Lis\u00e4\u00e4 ostoskoriin&quot; -tekstit. My\u00f6s ne, jotka olivat alun perin &quot;Valitse vaihtoehdot&quot; (muuttuvat tuotteet) tai &quot;Lue lis\u00e4\u00e4&quot; (ostamattomat tuotteet &#8211; ei hintaa tai loppu). Jos haluat hienos\u00e4\u00e4t\u00e4\u00e4, sis\u00e4llyt\u00e4 toinen argumentti n\u00e4ihin suodattimiin; tuotteen kohde. K\u00e4yt\u00e4 tuoteobjektia tulosteen ehdolliseen ohjaamiseen. Esimerkiksi tuotetyypin mukaan tai voiko tuotetta ostaa vai ei:<\/p>\n<pre><code>add_filter('woocommerce_product_add_to_cart_text', function($text, $product) {\n    if ($product-&gt;is_type('variable')) {\n        return __('Take your pick', 'txtdomain');\n    }\n    if (!$product-&gt;is_purchasable()) {\n        return __('Read more', 'txtdomain');\n    }\n    return $text;\n}, 10, 2);<\/code><\/pre>\n<h2>Muuta muuttuvien ja ryhmitettyjen tuotteiden hintaluokan tuotantoa<\/h2>\n<p>Oletuksena WooCommerce n\u00e4ytt\u00e4\u00e4 alimman ja korkeimman hinnan muuttuville ja ryhmitetyille tuotteille, joiden v\u00e4liss\u00e4 on &quot;-&quot;. Voit helposti muokata t\u00e4t\u00e4 alueen l\u00e4ht\u00f6\u00e4. Varmista esimerkiksi, ett\u00e4 se n\u00e4ytt\u00e4\u00e4 vain alhaisimman hinnan muodossa &quot;From:&quot;. WooCommercessa on yksi suodatin muuttuville tuotteille ja toinen ryhmitetyille tuotteille, joten katsotaanpa niit\u00e4 molempia vuorotellen.<\/p>\n<p>Muuttuvien tuotteiden hintaluokan HTML-tulostuksen hallinta tapahtuu suodattimella <code>woocommerce_variable_price_html<\/code>. Tuoteobjekti annetaan toisena argumenttina.<\/p>\n<p>Toiminnon sis\u00e4ll\u00e4 meid\u00e4n on haettava kaikki hinnat. WooCommerce tarjoaa k\u00e4tev\u00e4n toiminnon muuttuville tuoteobjekteille, <code>get_variation_prices()<\/code>. T\u00e4m\u00e4 palauttaa joukon kaikkia muunnelmien hintoja lajiteltuna alhaisin ensin. Kaikki mit\u00e4 meid\u00e4n tarvitsee tehd\u00e4, jos hintataulukon ensimm\u00e4inen elementti avautuu ja tulostetaan kauniisti:<\/p>\n<pre><code>add_filter('woocommerce_variable_price_html', function($html, $product) {\n    $prices = $product-&gt;get_variation_prices(true);\n    $from_price = wc_price(current($prices['price']));\n    return sprintf(__('From: %s', 'txtdomain'), $from_price. $product-&gt;get_price_suffix());\n}, 10, 2);<\/code><\/pre>\n<p>Ryhmitettyjen tuotteiden hintaluokan HTML-tulostussuodatin on hyvin samanlainen kuin muuttuvat tuotteet, mutta yhdell\u00e4 erolla; joukko kaikkien ryhmiteltyjen tuotteiden &quot;lasten&quot; hintoja on sis\u00e4llytetty suodattimen argumenttina. K\u00e4ytett\u00e4v\u00e4 suodatin on <code>woocommerce_grouped_price_html<\/code>:<\/p>\n<pre><code>add_filter('woocommerce_grouped_price_html', function($html, $product, $child_prices) {\n    $from_price = wc_price(current($child_prices));\n    return sprintf(__('From: %s', 'txtdomain'), $from_price. $product-&gt;get_price_suffix());\n}, 10, 3);<\/code><\/pre>\n<h2>Muokkaa varastotilan tekstitulostusta<\/h2>\n<p>Jos olet aktivoinut varastotilanteen n\u00e4ytt\u00e4misen WooCommerce-asetuksissa, sen pit\u00e4isi n\u00e4ytt\u00e4\u00e4 tarkka varaston m\u00e4\u00e4r\u00e4 yksitt\u00e4isess\u00e4 tuoten\u00e4kym\u00e4ss\u00e4 (esim. &#8221;42 varastossa&quot;). Voit kuitenkin muokata tulosta n\u00e4ytt\u00e4m\u00e4\u00e4n sen sijaan alueen tarkan m\u00e4\u00e4r\u00e4n sijaan. Tai vain &quot;varastossa&quot;, jos haluat piilottaa numeron.<\/p>\n<p>Suodatin t\u00e4m\u00e4n tekemiseen on <code>woocommerce_get_stock_html<\/code>ja jos sis\u00e4llyt\u00e4t toisen argumentin, saat tuoteobjektin. Tuoteobjektilla voit tehd\u00e4 tarvittavat toiminnot l\u00e4hd\u00f6n hienos\u00e4\u00e4t\u00f6\u00f6n. Muista, ett\u00e4 suodatettava tuloste on k\u00e4\u00e4ritty <code>&lt;p&gt;<\/code>elementin sis\u00e4\u00e4n, ja my\u00f6s tulostesi tulee olla.<\/p>\n<p>Pelk\u00e4st\u00e4\u00e4n &quot;varastossa&quot; tai &quot;ei varastossa&quot; n\u00e4ytt\u00e4miseen riitt\u00e4\u00e4 t\u00e4m\u00e4:<\/p>\n<pre><code>add_filter('woocommerce_get_stock_html', function($html, $product) {\n    if ($product-&gt;is_in_stock()) {\n        return sprintf('&lt;p class=\"stock in-stock\"&gt;%s&lt;\/p&gt;', __('In stock', 'txtdomain'));\n    } else {\n        return sprintf('&lt;p class=\"stock out-of-stock\"&gt;%s&lt;\/p&gt;', __('Out of stock', 'txtdomain'));\n    }\n    return $html;\n}, 10, 2);<\/code><\/pre>\n<p>Osakkeen n\u00e4ytt\u00e4minen &quot;aluearvoissa&quot; voidaan tehd\u00e4 seuraavasti:<\/p>\n<pre><code>add_filter('woocommerce_get_stock_html', function($html, $product) {\n    $current_stock = $product-&gt;get_stock_quantity();\n    if ($current_stock &lt;= 0) {\n        $new_html = __('Out of stock', 'txtdomain');\n    } else if ($current_stock &gt; 500) {\n        $new_html = sprintf('500+ %s', __('in stock', 'txtdomain'));\n    } else if ($current_stock &gt; 100) {\n        $new_html = sprintf('100+ %s', __('in stock', 'txtdomain'));\n    } else if ($current_stock &gt; 20) {\n        $new_html = sprintf('20+ %s', __('in stock', 'txtdomain'));\n    } else {\n        $new_html = __('In stock', 'txtdomain');\n    }\n    return sprintf('&lt;p class=\"stock\"&gt;%s&lt;\/p&gt;', $new_html);\n}, 10, 2);<\/code><\/pre>\n<h2>Nime\u00e4 tilausten tilat uudelleen<\/h2>\n<p>Joskus asiakas haluaa eri tarroja tilausten tiloihin, jotta ne olisivat j\u00e4rkev\u00e4mpi\u00e4 verkkokauppak\u00e4yt\u00e4nt\u00f6jens\u00e4 mukaan. Saatat esimerkiksi haluta, ett\u00e4 &quot;Pidossa&quot; nimet\u00e4\u00e4n uudelleen muotoon &quot;L\u00e4hett\u00e4m\u00e4t\u00f6n&quot; tai &quot;Valmis&quot; nimet\u00e4\u00e4n uudelleen &quot;L\u00e4hetetyksi&quot;. Vain jotta olisi j\u00e4rkev\u00e4mp\u00e4\u00e4, mitk\u00e4 tilaukset on l\u00e4hetett\u00e4v\u00e4 ja mitk\u00e4 on jo l\u00e4hetetty. WooCommerce tarjoaa yksinkertaisen suodattimen, <code>wc_order_statuses<\/code>, kaikille saatavilla oleville tilaustilojen nimille.<\/p>\n<pre><code>add_filter('wc_order_statuses', function($order_statuses) {\n    $order_statuses['wc-on-hold'] = __('Unsent', 'txtdomain');\n    $order_statuses['wc-completed'] = __('Sent', 'txtdomain');\n    return $order_statuses;\n});<\/code><\/pre>\n<p>K\u00e4ytett\u00e4viss\u00e4 olevat n\u00e4pp\u00e4imet ovat <code>wc-pending<\/code>, <code>wc-processing<\/code>, <code>wc-on-hold<\/code>, <code>wc-completed<\/code>, <code>wc-cancelled<\/code>, <code>wc-refunded<\/code>, ja <code>wc-failed<\/code>.<\/p>\n<p><div id=\"PostUnique_PostSource\" style=\"padding-top: 50px\">:  <a target=\"_blank\" rel=\"noopener nofollow\" href=\"\/\/awhitepixel.com\" class=\"external external_icon\">awhitepixel.com<\/a><\/div><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Pieni\u00e4, mutta hy\u00f6dyllisi\u00e4 koodiesimerkkej\u00e4, a-ha:ta ja ohjeita yleisist\u00e4 muutoksista eri tekstitulosteisiin WordPress WooCommercessa.<\/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,895,813,1110,843,813,843,854,854,864,864],"tags":[1166],"class_list":["post-233350","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-koodi","category-laajennuksia","category-n-a","category-opetusohjelmia","category-woocommerce-5","category-wordpress-5","tag-affiai-fi"],"_links":{"self":[{"href":"https:\/\/wordpress.mediadoma.com\/fi\/wp-json\/wp\/v2\/posts\/233350","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=233350"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.mediadoma.com\/fi\/wp-json\/wp\/v2\/posts\/233350\/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=233350"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/fi\/wp-json\/wp\/v2\/categories?post=233350"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/fi\/wp-json\/wp\/v2\/tags?post=233350"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}