最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - How to hide products that do not have an image from a slider carousel for an ecommerce webpage?

programmeradmin0浏览0评论

I am using a plugin for a product carousel on an ecommerce webpage. I would like to hide products that do not have images from the carousel. I am very new to all of this. It is my first webpage ever, and I have limited programming knowledge - but I'm willing to learn.

From what I have found so far, there is a filter hook for product item wrapper class. You can access product id from $args variable like $product_id = $args['product_id']; Then you should be able to conditionally add a hidden class to item wrapper by checking if a product image exists or not.

This is what I have tried without success (php):

add_filter('wcps_slider_item_class','wcps_slider_item_class_20200303', 10, 2);

function wcps_slider_item_class_20200303($class, $args){
    $product_id = isset($args['product_id']) ? $args[‘product_id’] : '';
    $class .= ' my-custom-class';
    if ($product_id->get_image() && $product_id->get_image() == 'no_selection') {
        $class =' .hidden {
        display: none;';
    }
    return $class;
}

If anyone can help it is greatly appreciated.

发布评论

评论列表(0)

  1. 暂无评论