{"id":6502,"date":"2021-11-20T11:40:16","date_gmt":"2021-11-20T11:40:16","guid":{"rendered":"https:\/\/musilda.cz\/?p=6502"},"modified":"2021-11-20T11:40:16","modified_gmt":"2021-11-20T11:40:16","slug":"jak-pridat-vlastni-polozku-do-hromadnych-akci-produktu","status":"publish","type":"post","link":"https:\/\/affinite.io\/cs\/jak-pridat-vlastni-polozku-do-hromadnych-akci-produktu\/","title":{"rendered":"Jak p\u0159idat vlastn\u00ed polo\u017eku do hromadn\u00fdch akc\u00ed produkt\u016f"},"content":{"rendered":"\n
Jednou z pom\u011brn\u011b obt\u011b\u017euj\u00edc\u00edch v\u011bc\u00ed u WooCommerce, je nutnost neust\u00e1le n\u011bco rozklik\u00e1vat. Na\u0161t\u011bst\u00ed je mo\u017en\u00e9 vyu\u017e\u00edt hromadn\u00e9 akce v adminu WooCommerce.<\/p>\n\n\n\n Do roletky pro hromadn\u00e9 akce lze p\u0159idat dal\u0161\u00ed polo\u017eku pomoc\u00ed k\u00f3du:<\/p>\n\n\n\n Tento filtr v\u00e1m umo\u017en\u00ed roz\u0161\u00ed\u0159it volbu hromadn\u00fdch akc\u00ed, j\u00e1 jsem jako p\u0159\u00edklad pou\u017eil nastaven\u00ed stavu skladu produktu. <\/p>\n\n\n\n V\u00fdhoda hromadn\u00e9 akce je v tom \u017ee si za\u0161krtnete, kter\u00e9 produkty chcete upravit: <\/p>\n\n\n\n Po za\u0161krtnut\u00ed a kliknut\u00ed na pou\u017e\u00edt, se provede funkce, kter\u00e1 je zaregistrovan\u00e1 do hooku handle_bulk_actions-edit-product:<\/p>\n\n\n\n Jak m\u016f\u017eete vid\u011bt, funkce p\u0159ijme id akce a pole produkt\u016f, kter\u00e9 jsou ozna\u010den\u00e9. N\u00e1sledn\u011b si vyvol\u00e1me objekt ka\u017ed\u00e9ho produktu, nastav\u00edme stav skladu a ulo\u017e\u00edme. <\/p>\n\n\n\n<\/a><\/figure>\n\n\n\n
add_filter( 'bulk_actions-edit-product', 'musilda_product_bulk_actions', 20, 1 );\nfunction musilda_product_bulk_actions( $actions ) {\n\n\t$actions['set-outofstock'] = __( 'Produkt nen\u00ed skladem', 'musilda' );\n\treturn $actions;\n\n}<\/code><\/pre>\n\n\n\n
<\/a><\/figure>\n\n\n\n
<\/a><\/figure>\n\n\n\n
add_filter( 'handle_bulk_actions-edit-product', 'musilda_handle_product_bulk_actions', 10, 3 );\nfunction musilda_handle_product_bulk_actions( $redirect_to, $action, $post_ids ) {\n\n\tif ( $action !== 'set-outofstock' ) {\n\t\treturn $redirect_to;\n\t}\n\n\tforeach ( $post_ids as $post_id ) {\n\n\t\t$product = wc_get_product( $post_id );\n\n\t\tif ( !empty( $product ) && is_object( $product ) ) {\n\n\t\t\t$product->set_stock_status( 'outofstock' );\n\t\t\t$product->save();\n\n\t\t}\n\n\t}\n\n\treturn $redirect_to;\n\n}<\/code><\/pre>\n\n\n\n