问题
I have a custom field for woocommerce products. This field outputs an image in woocommerce emails. However, since I'm using Woocommerce Bookings (custom product type) plugin as well, upon confirmation of the booking, my site crashes down. This is the code that output custom field:
//adds image to header
add_action('woocommerce_email_header', 'wcv_ingredients_email_logo', 10, 2);
function wcv_ingredients_email_logo( $email_heading, $email ){
if($email->object){
foreach($email->object->get_items() as $item_values){
// Get the product ID for simple products (not variable ones)
$product = $item_values->get_product();
$image_id = get_post_meta( $product->get_id(), 'store_logo_email', true ); //get the image ID associated to the product
$image_src = wp_get_attachment_image_src( $image_id, 'medium' )[0]; //get the src of the image - you can use 'full', 'large', 'medium', or 'thumbnail' here,
$image = '<div align="center"><img src="'.$image_src.'"></div>'; //create the img element
echo $image . '<br>'; //echo the image
}
}
}
This is the error that I'm getting in the logs:
Error Details ============= An error of type E_ERROR was caused in line 467 of the file /home/runcloud/webapps/wordpress/wp-content/themes/theme-wp/functions.php. Error message: Uncaught ArgumentCountError: Too few arguments to function wcv_ingredients_email_logo(), 1 passed in /home/runcloud/webapps/wordpress/wp-includes/class-wp-hook.php on line 286 and exactly 2 expected in /home/runcloud/webapps/wordpress/wp-content/themes/theme-wp/functions.php:467 Stack trace: #0 /home/runcloud/webapps/wordpress/wp-includes/class-wp-hook.php(286): wcv_ingredients_email_logo('Booking Confirm…') #1 /home/runcloud/webapps/wodpress/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters('', Array) #2 /home/runcloud/webapps/wordpress/wp-includes/plugin.php(465): WP_Hook->do_action(Array) #3 /home/runcloud/webapps/wordpress/wp-content/plugins/woocommerce-bookings/templates/emails/customer-booking-confirmed.php(23): do_action('woocommerce_ema…', ‘Booking Confirm…’) #4 /home/runcloud/webapps/wordpress/wp-content/plugins/woocommerce/includes/wc-core-functions.php(249): include('/home/runcloud/…') #5 /home/runcloud/webapps/wordpress/wp-content/plugins/woocommerce-bookings/includes/emails/class-wc-email-booki
来源:https://stackoverflow.com/questions/57639007/fatal-error-when-woocommerce-custom-field-is-triggered