在Woocommerce存档页面中添加产品字幕

时间:2018-09-29 02:31:59

标签: php wordpress woocommerce product hook-woocommerce

我可以通过将以下代码添加到single-product / title.php中为产品标题添加字幕:

the_title( '<h1 class="product_title entry-title">', '</h1>' );
echo "<p>My subtile</p>";

问题在于,它仅出现在产品页面上。不在其他视图(例如商店视图)上

enter image description here

我到处都是,找不到WooCommerce商店其他视图的标题吗?

1 个答案:

答案 0 :(得分:1)

已更新-要在商店等档案页面中添加产品字幕,请执行以下操作:

var cats = [[String:AnyObject]]()

func getAllCats(){
        _ = EZLoadingActivity.show("Loading...", disableUI: true)

        let param: [String: AnyObject] = ["apiKey": "???" as AnyObject]
        _ = Alamofire.request(APIRouters.GetAllCats(param)).responseJSON { (responseData) -> Void in
            if((responseData.result.value) != nil) {

                let getJson = JSON(responseData.result.value!)

                if (getJson["status"].stringValue == "200"){

                    if let resData = getJson["data"].arrayObject {
                        self.cats = resData as! [[String:AnyObject]]
                    }


                } else if (getJson["status"].stringValue == "404") {

                } else {

                }

            }

            _ = EZLoadingActivity.hide()
        }
    }

 var buttonY: CGFloat = 20  // our Starting Offset, could be 0
        for villain in cats {

            print("ok",villain["pt_name_Fa"])

            let villainButton = UIButton(frame: CGRect(x: 50, y: buttonY, width: 250, height: 30))
            buttonY = buttonY + 50  // we are going to space these UIButtons 50px apart

            villainButton.layer.cornerRadius = 10  // get some fancy pantsy rounding
            villainButton.backgroundColor = UIColor.darkGray
            villainButton.setTitle("Button for Villain: \(villain["pt_name_Fa"] ?? "" as AnyObject))", for: UIControlState.normal) // We are going to use the item name as the Button Title here.
            villainButton.titleLabel?.text = "\(villain)"
            villainButton.addTarget(self,action:#selector(villainButtonPressed),
                                    for:.touchUpInside)
            //            villainButton.addTarget(self, action: Selector(("villainButtonPressed:")), for: UIControlEvents.touchUpInside)

            self.view.addSubview(villainButton)  // myView in this case is the view you want these buttons added
        }

代码进入您的活动子主题(或活动主题)的function.php文件中。经过测试,可以正常工作。