Domanda

function initial_product_data ( $post_id ) {
// lets get out of here if this is not a new product
if ( 'product' != $_POST['post_type'] )
    return;

// make sure the post isn't automagically featured
// WTF WooCommerce??!!
update_post_meta( $post_id, '_featured', 'no' );

// automatically set the swatch
update_post_meta( $post_id, '_swatch_type', 'pickers' );    
update_post_meta( $post_id, '_swatch_type_options', unserialize('a:1:{s:7:"pa_size";a:4:{s:4:"type";s:12:"term_options";s:6:"layout";s:7:"default";s:4:"size";s:19:"swatches_image_size";s:10:"attributes";a:3:{s:7:"x-large";a:3:{s:4:"type";s:5:"color";s:5:"color";s:7:"#FFFFFF";s:5:"image";s:1:"0";}s:23:"x-large-toplarge-bottom";a:3:{s:4:"type";s:5:"color";s:5:"color";s:7:"#FFFFFF";s:5:"image";s:1:"0";}s:23:"x-small-topsmall-bottom";a:3:{s:4:"type";s:5:"color";s:5:"color";s:7:"#FFFFFF";s:5:"image";s:1:"0";}}}}') );
}

add_action( 'wp_insert_post', 'initial_product_data' );

Il codice funziona bene e quasi fa quello che dovrebbe fare. Tuttavia, sembra che si accenda ogni volta Un prodotto viene salvato e l'utente non può modificare i valori impostati sulla creazione iniziale del prodotto.

Eventuali suggerimenti? O questo è un bug wordpress?

Nessuna soluzione corretta

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a wordpress.stackexchange
scroll top