{"id":1476,"date":"2022-04-05T18:33:00","date_gmt":"2022-04-05T18:33:00","guid":{"rendered":"https:\/\/pppcreative.sk\/?p=1476"},"modified":"2022-07-05T11:27:04","modified_gmt":"2022-07-05T09:27:04","slug":"wordpress-snippety","status":"publish","type":"post","link":"https:\/\/www.areaweb.sk\/cs\/wordpress-snippety\/","title":{"rendered":"WordPress snippety"},"content":{"rendered":"<p class=\"wp-block-paragraph\">Sekcia kr\u00e1tkych ale u\u017eito\u010dn\u00fdch snippetov pre Woocomerce a WordPress.<\/p>\n\n\n\n<div style=\"height:65px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Uprav\u00ed zobrazovanie dostupnosti pre v\u0161etky produkty ktor\u00e9 za\u010d\u00ednaj\u00fa k\u00f3dom XXX<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/**\n* Change text if product sku start XXX\n*\/\nadd_filter( 'woocommerce_get_availability', 'filter_wc_get_availability', 10, 2);\nfunction filter_wc_get_availability( $availability, $product ) {\n    \/\/ In Stock\n\n    if ( $product-&gt;is_on_backorder() ){\n        $product_sku = $product-&gt;get_sku();\n        $kod = substr($product_sku,0,3);\n        if (  $kod =='XXX' ) {\n            \/\/ $stock_quantity = $product-&gt;get_stock_quantity();\n            \/\/ if (  $stock_quantity&lt;=0 ) {\n                $availability&#91;'availability'] = 'Tu sa zobraz\u00ed nastaven\u00e1 dostupnos\u0165';\n            \/\/ }\n        }\n    }\n         \n    return $availability;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Zobraz\u00ed ID produktov a EAN alebo \u010doko\u013evek \u010do nastav\u00edme iba vybran\u00e9mu pou\u017e\u00edvate\u013eovi alebo administr\u00e1torovi:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ zobrazi mne ID produktov\nadd_action( &#039;woocommerce_single_product_summary&#039;, &#039;zobraz_id_produktu&#039;);\nfunction zobraz_id_produktu(){\n   \/\/ if (current_user_can( &#039;administrator&#039; ) ){\n        global $current_user;\n        if ( $current_user-&gt;user_login == &#039;Meno pou\u017e&iacute;vate\u013ea&#039; ){\n\n        global $product;\n        echo &#039; ID produktu: &#039; . $product-&gt;get_ID();\n        echo &#039; &lt;br&gt; EAN: &#039; . get_post_meta( $product-&gt;get_ID(), &#039;ceske_sluzby_hodnota_ean&#039;, true );\n        }\n  \/\/  }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Vytvorenie vlastnej kol\u00f3nky pri produktoch<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/pridanie polia produktu\nif ( ! function_exists( 'create_custom_field' ) ) :\n    function create_custom_field() {\n        $args = array(\n        'id' =&gt; 'custom_field',\n        'label' =&gt; __( 'N\u00e1zov' ),\n        'class' =&gt; 'cfwc-custom-field',\n        'desc_tip' =&gt; true,\n        'description' =&gt; __( 'N\u00e1zov'),\n        );\n        woocommerce_wp_text_input( $args );\n    }\nendif;\nadd_action( 'woocommerce_product_options_inventory_product_data', 'create_custom_field' );\n\n   \/\/\/\/ulozenie hodnoty\nif ( ! function_exists( 'save_custom_field' ) ) :\n   function save_custom_field( $post_id ) {\n    $product = wc_get_product( $post_id );\n    $title = isset( $_POST&#91;'custom_field'] ) ? $_POST&#91;'custom_field'] : '';\n    $product-&gt;update_meta_data( 'custom_field', sanitize_text_field( $title ) );\n    $product-&gt;save();\n   }\nendif;\nadd_action( 'woocommerce_process_product_meta', 'save_custom_field' );<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Odstr\u00e1ni vybran\u00e9 polia z administr\u00e1cie produktu a z karty \u0161pecifik\u00e1cie na frontende na str\u00e1nke produktu.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function remove_tab($tabs){\n   if(!current_user_can('administrator') ){   \/\/ not enable function if user is admin\n        \/\/unset($tabs&#91;'general']); \/\/ it is to remove general tab\n        unset($tabs&#91;'inventory']); \/\/ it is to remove inventory tab\n        \/\/unset($tabs&#91;'advanced']); \/\/ it is to remove advanced tab\n        \/\/unset($tabs&#91;'linked_product']); \/\/ it is to remove linked_product tab\n        \/\/unset($tabs&#91;'attribute']); \/\/ it is to remove attribute tab\n        \/\/unset($tabs&#91;'variations']); \/\/ it is to remove variations tab\n   }\n    return($tabs);\n\n}\nadd_filter('woocommerce_product_data_tabs', 'remove_tab', 10, 1);\n\n\n\/\/ add_filter( 'wc_product_enable_dimensions_display', '__return_false' );  \/\/ remove \nspecification\n add_filter( 'woocommerce_product_get_weight' , '__return_false' );  \/\/ remove only weight from spcification<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Skrytie druhej platby ak je dostupn\u00e1 doprava zdarma<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ function pppcreative_unset_shipping_when_free_is_available_in_zone( $rates, $package ) {\n\/\/    \/\/ Only unset rates if free_shipping is available\n\/\/    if ( isset( $rates&#91;'free_shipping:2'] ) ) {   \/\/ zvolte podla hodnoty value v inpute doprava zdarma\n\/\/       unset( $rates&#91;'flat_rate:1'] );   \/\/ zvolte podla hodnoty value v inpute ktor\u00fd chcete skryt\n\/\/    }     \n\/\/    return $rates;\n\/\/ }<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Na str\u00e1nke sa pracuje&#8230;<\/p>","protected":false},"excerpt":{"rendered":"<p>Sekcia kr\u00e1tkych ale u\u017eito\u010dn\u00fdch snippetov pre Woocomerce a Wordpress. Uprav\u00ed zobrazovanie dostupnosti pre v\u0161etky produkty ktor\u00e9 za\u010d\u00ednaj\u00fa k\u00f3dom XXX \/** * Change text if product sku start XXX *\/ add_filter(\u2026<\/p>","protected":false},"author":1,"featured_media":1806,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[],"class_list":["post-1476","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-wordpress"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/www.areaweb.sk\/cs\/wp-json\/wp\/v2\/posts\/1476","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.areaweb.sk\/cs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.areaweb.sk\/cs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.areaweb.sk\/cs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.areaweb.sk\/cs\/wp-json\/wp\/v2\/comments?post=1476"}],"version-history":[{"count":0,"href":"https:\/\/www.areaweb.sk\/cs\/wp-json\/wp\/v2\/posts\/1476\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.areaweb.sk\/cs\/wp-json\/wp\/v2\/media\/1806"}],"wp:attachment":[{"href":"https:\/\/www.areaweb.sk\/cs\/wp-json\/wp\/v2\/media?parent=1476"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.areaweb.sk\/cs\/wp-json\/wp\/v2\/categories?post=1476"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.areaweb.sk\/cs\/wp-json\/wp\/v2\/tags?post=1476"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}