Created
March 23, 2023 09:32
-
-
Save FrancoStino/c9f18f9fd5e8dfdec90c33cceb917251 to your computer and use it in GitHub Desktop.
Capitalize Title Product on save automatically - Woocommerce
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Definiamo la funzione che sarà chiamata quando viene salvato un prodotto | |
function my_capitalize_product_title( $product_id ) { | |
// Recuperiamo il prodotto dal suo ID | |
$product = wc_get_product( $product_id ); | |
// Recuperiamo il titolo del prodotto | |
$title = $product->get_title(); | |
// Trasformiamo il titolo in Capitalize | |
$capitalized_title = ucwords( strtolower( $title ) ); | |
// Impostiamo il nuovo titolo al prodotto | |
$product->set_name( $capitalized_title ); | |
// Salviamo il prodotto con il nuovo titolo | |
remove_action( 'woocommerce_update_product', 'my_capitalize_product_title' ); | |
$product->save(); | |
} | |
// Aggiungiamo la funzione all'hook 'woocommerce_update_product' | |
add_action( 'woocommerce_update_product', 'my_capitalize_product_title' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment