触发Woocommerce自定义字段时出现致命错误

时间:2019-08-24 14:48:40

标签: php wordpress woocommerce hook-woocommerce

我对woocommerce产品有一个自定义字段。此字段在woocommerce电子邮件中输出图像。但是,由于我也使用了Woocommerce Bookings(自定义产品类型)插件,因此在确认预订后,我的网站崩溃了。这是输出自定义字段的代码:

//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
        }
    }
}

这是我在日志中遇到的错误:

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

0 个答案:

没有答案