产品名称 - 使用 elementor PRO 的动态请求参数

问题描述 投票:0回答:1

我使用 Elementor PRO 创建了一个产品模板页面。 我在这里放置了一个链接到联系页面的按钮。 如何将产品名称动态传递到联系页面 URL? 类似于 www.sitename.com/contacts?productname=**dynamicproductname**

谢谢 中号

wordpress elementor
1个回答
0
投票

这可以在给定的

JS Code
的帮助下实现。在这段代码中,我们从
Product Name
获取
product title
并将其与 URL 一起传递。要添加 JS 代码,请导航至 Elementor > Custom CSS & JS,然后切换到
JavaScript tab
,这里我们需要添加给定的代码。

jQuery(document).ready(function($) {

// Replace .elementor-button-class with the CSS class of your Elementor button.
$( '.elementor-button-class' ).each(function() {
    var productName = '';

    // Here we are fetching product name from the page title.
    productName = $(this).closest( '.elementor-template' ).find( '.elementor-heading-title' ).text().trim();

    // Here we are appending the product name to the button URL.
    var currentUrl = $(this).attr( 'href' );
    var newUrl = currentUrl + '?productname=' + encodeURIComponent(productName);
    $(this).attr('href', newUrl);
});

});

© www.soinside.com 2019 - 2024. All rights reserved.