【问题标题】:Wordpress - PHP : How can I get the selected data in a form into a text area?Wordpress - PHP:如何将表单中的选定数据放入文本区域?
【发布时间】:2023-03-11 15:40:01
【问题描述】:

我正在尝试收集插入表单(具有多个选择的表单 - 即带有单选按钮的表单)中的数据并将其插入文本区域。

表单是使用 wordpress 5.1 版的“额外产品选项”插件创建的 我使用 Elementor Pro (v3.4.2) 将短代码插入文本区域。

我想通过在我的子主题中写入 functions.php 文件中的简码来执行此操作。 问题是:我不知道该怎么做,我在谷歌上的搜索返回了没有很好的结果......

我只是从 wordpress 的支持论坛中找到了这个小代码,但这并不是我真正需要的,因为我没有购物车来获取数据。

$products = $woocommerce->cart->get_cart();

foreach($products as $key => $product) 
{ // Iterate cart items
    if (array_key_exists(“thwepof_options”,$product))
    {
        $data = $product[“thwepof_options”];
        if(!empty($data))
        {
            foreach($data as $item)
            { // Iterate item options
                //var_dump($item);
                echo $item[‘label’];
                echo $item[‘value’];
            }
        }
    }
}

谁能告诉我我需要什么类型的代码来解决这个问题?

【问题讨论】:

    标签: php wordpress woocommerce shortcode wordpress-shortcode


    【解决方案1】:
    add_shortcode('wporg', 'wporg_shortcode');
    function wporg_shortcode( $atts = [], $content = null) {
        // add radio/checkbox buttons to the $content
        // add some extra javascript logic if needed?
        // 
        // always return
        return $content;
    }
    

    https://developer.wordpress.org/plugins/shortcodes/basic-shortcodes/

    这就是您创建自定义简码的方式。不确定这是否是您的问题

    【讨论】:

    • 我的问题不在于如何创建简码。问题是我使用插件“Extra Product Options”创建了一个带有单选按钮的表单,并且我想使用简码(在按钮中实现)收集插入其中的所有数据(即:选择了哪些单选按钮)。但是我对 PHP 的了解还不够,无法编写一个短代码来执行此操作,并且当我在互联网上搜索此特定问题的解决方案时没有结果。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-06
    • 1970-01-01
    • 2010-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多