WordPress için en iyi 25 Woocommerce görüntülerim
Zaman geçti … Woothemes için tam zamanlı bir destek teknisyeni WooCommerce olarak çalışmaya başladığımdan bu yana 6 ay geçti.Bu 6 ay boyunca WooCommerce hakkında çok şey öğrendim ve WooCommerce ile ilgili görüntülerden çok fazla kod (çok fazla okuma!) Yaptım.Aslında, WooCommerce çok güçlü ve genişletilmiş bir araçtır.Neredeyse her şey için kullanılabilecek birçok kanca var ve WooCommerce’ı bu kadar iyi yapan şey bu.Aşağıda, son birkaç ay içinde yazdığım veya adapte olduğum snippet’lerin bir listesi;Bu görüntülerin tümü, tema klasörünüzdeki function.php dosyasına yapıştırılmalıdır:
1 – Ödeme türünü yönetici wooCommerce add_action e -posta (‘wooocommerce_email_after_table’, ‘add_payment_method_to_admin_new_order’, 15, 2) ekleyin; Function add_payment_method_to_admin_new_order ($ sipariş, $ is_admin_email) {if ($ is_admin_email) {echo ‘
ödeme yöntemi: ‘. $ sipariş-> ödeme_method_title. ‘
‘; }} Sayfa başına 2-up-Sell ürünleri / satır başına remove_action (‘woocommerce_affter_single_product_summary’, ‘woocommerce_upsel_display’, 15); Add_action (‘wooocommerce_aftle_single_product_summary’, ‘wooocommerce_output_upsells’, 15); if (! function_exists (‘wooocommerce_output_upsells’))) {function wooocommerce_output_upsells () {woocommerce_upsell_display (3.3); // 3 Ürünü 3}}} 3 – Add_action Shop sayfasından (‘pre_get_posts’, ‘Custom_prre_get_posts_query’) silin; Custom_pre_get_posts_query ($ q) işlevi {if (! $ Q-> is_main_query ()) dönüş; eğer (! $ q-> is_post_type_archive ()) döndürürse; if (! Is_admin () && is_shop () &&! Is_user_logged_in ()) {$ q-> set (‘Tax_query’, dizi (dizi (‘taksonomi’ => ‘ürün_cat’, ‘alan’ => ‘slug’, ‘ Terimler ‘=> dizi (‘ renk ‘,’ lezzet ‘,’ baharatlar ‘,’ vanilya ‘), // Bu kategorilerdeki ürünleri’ operatör ‘=>’ değil ‘)))))); } remove_ace (‘pre_get_posts’, ‘Custom_prre_get_posts_query’); } 4 – Dizeleri hızlı bir şekilde çevir ekD_filter (‘getText’, ‘cerreclate_text’); Add_filter (‘ngettext’, ‘
çevirisi_text ‘); Function Translate_text ($ Çeviri) {$ transled = str_ireplace (‘seç ve option’, ‘Select’, $ Çeviri); Dönüm $ tercüme; } 5 – woocommerce add_filter (‘wooCommerce_product_categories_widget_args’, ‘woo_product_cat_widget_args’); işlev woo_product_cat_widget_args ($ cat_args) {$ cat_args [‘hariç’] = array (’16 ‘); Dönüş $ cat_args; } 6 – Ürün varyasyonuna özel bir alan ekleyin // ekran alanlarını ekleyin add_action (‘wooocommerce_product_aft_variable_attributes’, ‘vary_fields’, 10, 2); // js yeni varyasyonlar için alanlar eklemek için add_ace (‘wooocommerce_product_aft_variable_atttribes_js’, ‘değişken_fields_js’); // varyasyon alanlarını kaydet add_ace (‘wooocommerce_process_product_meta_variable’, ‘değişken_fields_prosess’, 10, 1); Function Vary_fields ($ loop, $ varyation_data) {?>
$ Post_id) {if (isset ($ _post ['değişken_sku' ']] )))): $ değişken_sku = $ _post ['değişken_sku']; $ Varic_post_id = $ _Post ['Varic_post_id']; $ değişken_custom_field = $ _post ['my_custom_field']; ($ i = 0; $ i cart-> get_cart () olarak $ cart_item_key => $ değerler) {$ _product = $ değerler ['data']; if (get_the_id () == $ _product-> id) {return __ ('zaten sepette - tekrar ekle?', 'wooocommerce'); }} dönüş __ ('Sepete Ekle', 'Wooocommerce'); } / ** * Ürün arşivlerinde sepet metnine ekle değiştirin * / add_filter ('add_to_cart_text', 'woo_archive_custom_cart_button_text'); işlev woo_archive_custom_cart_button_text () {global $ wooocommerce; foreach ($ wooocommerce-> cart-> get_cart () olarak $ cart_item_key => $ değerler) {$ _product = $ değerler ['data']; if (get_the_id () == $ _product-> id) {return __ ('zaten sepette', 'wooocommerce'); }} dönüş __ ('Sepete Ekle', 'Wooocommerce'); } 9 - Add_filter kategorisindeki ürün sayısını gizle ('wooocommerce_subcategory_count_html', 'woo_remove_category_products_count'); İşlev woo_remove_category_products_count () {return;
} 10 - Bir hesap ödeme sütunu oluştur, gerekli add_filter ('wooocommerce_checkout_fields', 'woo_filter_account_checkout_fields'); işlev woo_filter_account_checkout_fields ($ fields) {$ fields ['hesabı'] ['hesap_username'] ['gerekli'] = true; $ fields ['hesabı'] ['hesap_password'] ['gerekli'] = true; $ Fields ['Hesap'] ['hesap_password-2'] ['gerekli'] = true; $ Fields Return; } 11 - Ürün sekmesinin adını değiştird_filter ('wooocommerce_product_tabs', 'woo_rename_tab', 98); işlev woo_rename_tab ($ tabs) {$ tabs ['açıklama'] ['başlık'] = 'daha fazla bilgi'; $ sekmeleri döndür; } 12 - Ürün kategorilerinin listesi woocommerce $ args = dizi ('numara' => $ numara, 'sipariş' => $ sipariş '=> $ sipariş,' hide_empty '=> $ Hide_Empty,' => dahil olmak üzere '=> dahil $ İds); $ ürün_categorileri = get_terms ('ürün_cat', $ args); $ count = count ($ product_categories); if ($ sayı> 0) {echo "
"; Foreach ($ ürün_categorisi olarak $ ürün_categorisi olarak) {echo '
. $ Product_category-> Adı. '
'; } echo "
"; } 13 - Add_filter Shop sayfasının başlığını değiştirin ('wooocommerce_page_title', 'woo_shop_page_title'); İşlev woo_shop_page_title ($ page_title) {if ('Shop' == $ page_title) {return "Yeni başlığımı döndür"; }} 14 - widget başlığını değiştir / * * Widget başlığını değiştir * / add_filter ('widget_title', 'woo_widget_title', 10, 3); İşlev woo_widget_title ($ başlık, $ örnek, $ id_base) {if ('onsale'
== $ id_base) {return "yeni başlığım"; }} 15 - Varsayılan ayarları sil wooCommerce add_filter ('wooocommerce_catalog_settings', 'woo_remove_catalog_options'); İşlev woo_remove_catalog_options ($ katalog) {unset ($ katalog [23]); // Zeros (no) Düzensiz ($ katalog [22]); // 2 ondalık basamalılar ($ katalog [21]); // ondalık sep (.) Unset ($ katalog [20]); // bin sep (,) unset ($ katalog [19]); // Para birimi konumu (solda) Unset ($ katalog [18]); // Para birimi konumu (solda) Unset ($ katalog [5]); // Ajax Sepete Ekle (hayır) $ katalog; } 16 - e -posta adresini "işlevinden değiştirin woo_custom_wp_mail_from () {global $ wooocommerce; html_entity_decode döndür ('[e -posta korumalı] ); } add_filter ('wp_mail_from', 'woo_custom_wp_mail_from', 99); 17 - WooCommerce işlevindeki adın kodunu çözün woo_custom_wp_mail_from_name () {global $ wooocommerce; dönüş html_entity_decode (get_option ('wooocommerce_email_from_name')); } add_filter ('wp_mail_from_name', 'woo_custom_wp_mail_from_name', 99); işlev woo_custom_wp_mail_from () {global $ wooocommerce; Dönüş html_entity_decode (get_option ('wooocommerce_email_from'))); } add_filter ('wp_mail_from_name', 'woo_custom_wp_mail_from_name', 99); 18 - Mükemmel ürün kimliği işlevini döndür woo_get_feated_product_ids () {// cache $ foredured_product_ids = get_trantient ('wc_featured_products'); // geçerli önbellek bulundu (false! $ featured = get_posts (dizi ('post_type' => dizi ('ürün', 'ürün_variation'), 'post_per_page' => -1, 'post_status' => 'yayın', '
meta_query '=> dizi (dizi (' tuş '=>' _visibility ',' değer '=> dizi (' katalog ',' görünür '),' karşılaştır '=>' in '), dizi (' anahtar '=> => => => '_featured', 'değer' => 'evet'), 'alanlar' => 'id => ebeveyn')); $ ürün_ids = array_keys ($ featured); $ parent_ids = array_values ($ featured); $ featured_product_ids = array_unique (array_merge ($ ürün_idleri, $ parent_ids)); set_transient ('wc_featured_products', $ featured_product_ids); Return $ feesured_product_ids; } 19 - Adres sayfasını düzenlemek için özel bir alan ekleyin // Adres sayfası işlevi düzenlemek için alan ekle woo_add_dit_address_fields ($ saha) {$ new_fields = array ('date_of_birth' => dizi ('etiket' => __ ('doğum tarihi doğum tarihi ',' wooocommerce '),' gerekli '=> false,' class '=> dizi (' form-satır '),); $ fields = array_merge ($ fields, $ new_fields); $ Fields Return; } add_filter ('wooocommerce_default_address_fields', 'woo_add_dit_address_fields'); 20 - Wooocommerce_sale_products ($ ATTS) tarafından satılan kısa ürün kataloğunu görüntüler {global $ wooocommerce_loop; Extract (Shortcode_atts (Array ('per_page' => '12', 'sütunlar' => '4', 'sipariş' => 'tarih', 'sipariş' => 'desc'), $ atts)); $ wooocommerce_loop ['sütunlar'] = $ sütunlar; $ args = Array ('Post_type' => 'ürün', 'Post_status' => 'yayınlama', 'IGNORE_STICKY_POSTS' => 1, 'Post_per_page' => $ per_page, 'sipariş' => $ siparişby, 'sipariş' = >
$ sipariş, 'meta_query' => dizi (dizi ('anahtar' => '_visibility', 'değer' => dizi ('katalog', 'görünür'), 'karşılaştır' => 'in'), dizi (' tuş '=>' _sale_price ',' değer '=> 0,' karşılaştır '=>'> ',' type '=>' sayısal '))); Query_posts ($ args); Ob_start (); wooocommerce_get_template_part ('loop', 'dükkan'); wp_reset_query (); return ob_get_clean (); } add_shortcode ('sale_products', 'wooocommerce_sale_products'); 21 - WOO_HAVE_ONSALE_PRODUCTS () satılan bir ürüne sahiptir {Global $ wooocommerce; // Ürünleri Satış Alın $ ürün_ids_on_sale = array_filter (wooocommerce_get_product_ids_on_sale ()); if (! boş ($ ürün_ids_on_sale)) {return true; } else {return false; }} // örnek: if (woo_have_onsale_products ()) {echo 'onsale ürünleri var'; } else {echo 'onsale ürün no'; } 22 - Minimum add_aason sayısını belirleyin ('wooocommerce_checkout_princess', 'wc_minimum_order_amount'); İşlev wc_minimum_order_amount () {global $ wooocommerce; $ minimum = 50; if ($ wooocommerce-> cart-> get_cart_total (); add_error (sprintf ('Siparişinizi vermek için minimum %s olan bir siparişe sahip olmalısınız.', $ minimum); }} 23 - Add_filter mağaza sayfasındaki fiyat, tarih veya başlığa dayalı mesaj ('wooocommerce_default_catalog_orderby', 'Custom_default_catalog_orderby'); Custom_default_catalog_orderby () {return 'tarih' işlevi; // Başlık ve Fiyatı da kullanabilir} 24 - Mahşum ekle düğmesine ekle düğmesine direk add_filter sayfasına ('
add_to_cart_redirect ',' regirect_to_checkout ');Function regirect_to_checkout () {global $ wooocommerce;$ checkout_url = $ wooocommerce-> cart-> get_checkout_url ();return $ checkout_url;} 25 - Sipariş bittiğinde e -postanın alıcısını ekle woo_extra_email_recipient ($ alıcı, $ object) {$ alıcı = $ alıcı.', [e -posta korumalı] ';Dönüş $ alıcı;} add_filter ('wooocommerce_email_recipient_customer_completed_order', 'woo_extra_email_recipient', 10, 2);Ve bu kadar!Umarım bu fragmanı yararlı bulursunuz, her şey test edilir ve her şey iyi çalışır, ancak sorun yaşarsanız bana yorumlar bölümünde söyleyin.İyi vakit geçir!