WooCommerce自动获取产品ID

时间:2017-03-17 14:53:45

标签: php wordpress woocommerce

我需要在单品页面内容中输出WooCommerce产品ID。我有一个表格,显示了几行不同的东西,但这个表格非常适合显示所有页面产品。但是,当有人点击产品时,我想将其呈现在单个产品页面中。我没有运气。

<?php echo do_shortcode( sprintf( '[product_table include="" columns="date,tax:remixer,name:Track Name,tax:bpm,categories:Genre,cf:preview,add-to-cart:Buy,price" shortcodes="true" display_page_length="false" links="none" sort_by="date"]', get_queried_object_id() ) ); ?>

这就是我所拥有的,但我确信这是非常错误的。

 include="<?php $id = $product->id;(); ?>"

2 个答案:

答案 0 :(得分:0)

"' . get_the_ID() . '"

是正确的方法!

答案 1 :(得分:0)

VGR有一个Woocommerce的github存储库,你可以看到你应该编辑哪些钩子。

像:

    this.PDFReports = function () {

        var reports = JSON.parse(localStorage.getItem("reportsInfo"))

        var reportPDFPaths = []

        $.each(reports, function (index, r) {

            //No need to render report as PDF if it is already.
            if (r.TypeName != "PDF") {

                var reportid = r.BOReportID
                var parms = r.parms
                var parmslength = Object.keys(parms).length
                var parmstring = ""

                for (i = 0; i < parmslength; i++) {
                    var parmname = parms[i].name
                    var parmvalue = parms[i].value

                    if (parmstring.length > 0) {
                        parmstring = parmstring + "|Name:" + parmname + "," + "Value:" + parmvalue
                    }
                    else {
                        parmstring = parmstring + "Name:" + parmname + "," + "Value:" + parmvalue
                    }

                }

                //Render crystal report as PDF file. 
                var PDFCreateUrl = "/odata/PDFReport"
                PDFCreateAjaxRequest("post", PDFCreateUrl, { ReportID: reportid, ParmString: parmstring })
                                .done(function (result) {
                                    reportPDFPaths.push(result.value)

                                })
                               .fail(function (jqXHR, textStatus, errorThrown) {
                               });

                function PDFCreateAjaxRequest(type, url, data) {
                    var options = {
                        dataType: "json",
                        contentType: "application/json",
                        type: type,
                        data: data ? JSON.stringify(data) : null,
                        async: false
                    };
                    return $.ajax(url, options);
                }

            }
            else
            {
                var ReportID = r.ReportID
                var fullpath = localStorage.getItem("PDFServerPath" + ReportID)
                reportPDFPaths.push(fullpath)
            }

        })


        localStorage.setItem("reportPDFPaths", reportPDFPaths)
    }