小编Joe*_*tie的帖子

WooCommerce - 提交后检索选择框的正确数据值

我正在使用 Woocommerce,并且在管理面板中建立了一个选择框。我通过平面文件填充选择框中的信息。一切正常(几乎)。

我被卡住的部分是在我选择了我想要的“选择”并保存我得到数组$key位置而不是实际的$value. 我很接近,但我不能把我的手指放在它上面。

更新:这是我的完整代码:

function woo_add_custom_admin_product_tab() {
?>
    <li class="custom_tab"><a href="#custom_tab_data"><?php _e('Additional Information', 'woocommerce'); ?></a></li>
<?php
}
add_action( 'woocommerce_product_write_panel_tabs', 'woo_add_custom_admin_product_tab' );


function woo_add_custom_admin_fields() {    
    global $woocommerce, $post;

    echo '<div id="custom_tab_data" class="panel woocommerce_options_panel">';
    echo '<div class="options_group">';

    // Select - Breed1
    if (file_exists ( plugin_dir_path(__FILE__) .'breed.txt')) {
        $breedData = file_get_contents ( plugin_dir_path(__FILE__) .'breed.txt');
        $breedArray = explode ("\n", $breedData);
    }

    woocommerce_wp_select(array(
        'id'      => '_select_breed1',
        'label'   => __( 'Select Primary Breed', 'woocommerce' ),
        'desc_tip'    => 'true',
        'description' => __( …
Run Code Online (Sandbox Code Playgroud)

php arrays wordpress html-select woocommerce

5
推荐指数
1
解决办法
1025
查看次数

使用 function.php 的单一产品上的 Woocommerce 元数据

我正在努力通过我的functions.php 获取元数据以正确过滤。

如果我在我的子主题中编辑 meta.php 没有问题,我可以让它工作: 与 meta.php 一起使用 (简短的故事 - 但因为我使用的是 Avada 主题 - 他们在升级时更改了子主题的位置,我选择了 functions.php)

我目前正在尝试以这种方式过滤元数据:

add_filter ('woocommerce_product_meta_start','add_pet_info' );
function add_pet_info($pet_info) {
$string ="Test Text";
return $pet_info . $string; }
Run Code Online (Sandbox Code Playgroud)

我想得到这个结果: 我想要的是 但我就是无法让它工作。

任何想法我在这里缺少什么?

谢谢!

php meta wordpress filtering woocommerce

4
推荐指数
1
解决办法
5557
查看次数

woocommerce_wp_select 来自产品属性术语的选项数组

我正在尝试在 woocommerce 中创建一个下拉列表框,但用数据库中的数据填充它。

我的大部分代码都在工作,但填充列表框的部分正在杀死我。这是我到目前为止。

add_action( 'woocommerce_product_options_general_product_data', 'woo_add_custom_general_fields' ); // Display Extra Fields on General Tab Section


add_action( 'woocommerce_process_product_meta', 'woo_add_custom_general_fields_save' ); // Save Fields

function woo_add_custom_general_fields() {
    global $woocommerce, $post, $product;
    echo '<div class="options_group">';

    // Select

    $options = array(
        'hide_empty' => false,
        'order' => 'ASC',
        'fields' => 'names'
        );
    $DogBreeds = get_terms('pa_breed', $options);

    foreach ($DogBreeds as $key => $value) {
        $theArray = "'{$value}'  => __( '{$value}' , 'woocommerce' ), ";
    }

    woocommerce_wp_select( 
        array( 
            'id'      => '_select', 
            'label'   => __( 'My Select …
Run Code Online (Sandbox Code Playgroud)

php wordpress attributes product woocommerce

2
推荐指数
1
解决办法
8713
查看次数