0

我正在寻找一种方法来根据我的输入字段在 WooCommerce 单一产品中设置我的价格,我有几个问题。这是我在 themefolder/functions.php 中的代码:

/* 
 >>> Custom Fields / SINGLE PRODUCT <<<
======================================== */


/* Add the field to the checkout */
add_action( 'woocommerce_single_product_summary', 'my_custom_checkout_field' );

function my_custom_checkout_field() {

    global $post;
$terms = wp_get_post_terms( $post->ID, 'product_cat' );
foreach ( $terms as $term ) $categories[] = $term->slug;


// start if statements

if ( in_array( 'grupa1', $categories ) ||  in_array( 'grupa2', $categories )
 ||  in_array( 'grupa3', $categories ) ||  in_array( 'grupa3a', $categories )
  ||  in_array( 'grupa4', $categories )  ||  in_array( 'grupa5', $categories ))

 {

// Set Width
echo '<div id="setWidth"><h2>' . __('Width') . '</h2>'  . '</br>';

woocommerce_form_field( 'setWidth', array(
'type' => 'text',
'class' => array('my-field-class form-row-wide'),
'label' => __('Your Width (cm.mm)')  . '</br>',
'placeholder' => __('40.25')

) );

echo '</div>';



// Set Height
echo '<div id="setHeight"><h2>' . __('Height') . '</h2>'  . '</br>';

woocommerce_form_field( 'setHeight', array(
'type' => 'text',
'class' => array('my-field-class form-row-wide'),
'label' => __('Podaj Height (cm.mm)')  . '</br>',
'placeholder' => __('80.60')

) );

echo '</div>';


}// end if in Grupa1-Grupa5


} // end function

如您所见,我的产品类别很少:Grupa1 ... Grupa5,在该类别中的每个产品中,上面的代码将添加 2 个输入,这是我的问题:-如何保存客户端从输入中输入的值并显示在订单页面上('woocommerce_email_order_meta_keys') - 如何设置和保存我的价格,例如:输入宽度 >=40 && <=80 输入高度 >=60 && <=90 然后价格=myValue 其他...

我知道这很复杂,我已经尝试了很多插件和表单,但没有结果——只是浪费了我的时间和金钱;/

4

0 回答 0