Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Woocommerce将默认产品图像更改为其类别图像_Php_Wordpress_Woocommerce - Fatal编程技术网

Php Woocommerce将默认产品图像更改为其类别图像

Php Woocommerce将默认产品图像更改为其类别图像,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,这是我的商业背景 我有几个类别,我们叫它们a,B,C,D,E…等等 从后端,我为每个类别提供了类别图像 现在,假设我在没有选择任何图片的情况下发布类别a中的产品 该产品仅显示默认图像(灰色背景的图像) 当没有选择图像时,是否有方法将类别图像用作默认产品图像 我尝试了一些代码,这是我最后一个: add_action( 'init', 'custom_fix_thumbnail'); function custom_fix_thumbnail(){ add_filter('wc_plac

这是我的商业背景

我有几个类别,我们叫它们a,B,C,D,E…等等

从后端,我为每个类别提供了类别图像

现在,假设我在没有选择任何图片的情况下发布类别a中的产品

该产品仅显示默认图像(灰色背景的图像)

当没有选择图像时,是否有方法将类别图像用作默认产品图像

我尝试了一些代码,这是我最后一个:

add_action( 'init', 'custom_fix_thumbnail');

function custom_fix_thumbnail(){

    add_filter('wc_placeholder_img_src', 'custom_woocommerce_placeholder_img_src');

    function custom_woocommerce_placeholder_img_src( $src ) {
        if (is_shop() || is_singular('product') || is_archive() || is_checkout() || is_cart()) {
            global $post;
            $array = get_the_terms($post->ID, 'product_cat');
            reset($array);
            $first_key = key($array);
            $thumbnail_id = get_woocommerce_term_meta($first_key, 'thumbnail_id', true);

            // get the image URL for parent category
            $image = wp_get_attachment_url($thumbnail_id);

            // print the IMG HTML for parent category
            if ($image)
                $src = $image;

        }
        return $src;
    }
}

尝试将钩子更改为
woocommerce\u占位符\u img\u src
wc\u占位符\u img\u src
似乎已被弃用