Wie kann ich das Platzhalter-Bild für Produkte in WooCommerce austauschen
Marc Wagner
Februar 2, 2023
Bei der Installation von WooCommerce wird automatisch ein Platzhalter-Bild für die Produkte angelegt und in die Datenbank eingetragen. Wie du dieses Bild bequem austauschen kannst, möchte ich dir heute in dieser Anleitung demonstrieren.
option_{$option} #
Als Erstes lädst du über die Mediathek das gewünschte Bild in deine WordPress Umgebung hoch. Anschließend sicherst du dir den Pfad zur Datei. Den Pfad findest du in den Anhang Details.
Anschließend wechselst du in die functions.php deines Child-Themes und fügst dort das folgende PHP Snippet ein:
/**
* @param $value
* @param $option
*
* @return mixed|string
*/
function wc_change_default_image($value, $option): string
{
if ('woocommerce_placeholder_image' !== $option) {
return $value;
}
// Add the path to the image, e.g.:
$src = '/wp-content/uploads/2023/02/beispiel.jpg';
// If the image does not exist return the default value
if (!file_exists(get_home_path() . $src)) {
return $value;
}
// return the image
return $src;
}
/*
* Filter: apply_filters( "option_{$option}", mixed $value, string $option )
*/
add_filter('option_woocommerce_placeholder_image', 'wc_change_default_image', 10, 2);Das war es auch schon. Nun wird immer anstatt dem Standard-Platzhalter Bild von WooCommerce dein Bild verwendet.
Viel Spaß damit.
Artikel von:
Marc Wagner
Hi Marc here. I’m the founder of Forge12 Interactive and have been passionate about building websites, online stores, applications and SaaS solutions for businesses for over 20 years. Before founding the company, I already worked in publicly listed companies and acquired all kinds of knowledge. Now I want to pass this knowledge on to my customers.

