【发布时间】:2021-10-23 16:21:20
【问题描述】:
我在结帐页面中有这个自定义复选框:
add_action('woocommerce_after_checkout_billing_form', 'checkout_shipping_form_packing_addition', 20);
function checkout_shipping_form_packing_addition()
{
$domain = 'woocommerce';
echo '<tr class="packing-select";>' . __('', $domain) . '<td>';
$chosen = WC()->session->get('chosen_packing');
// Add a custom checkbox field
$variable = <<<XYZ
<html>
<body>
<p style="font-size:15px; margin-top: -38px; margin-left: 5px; height:auto; border:1px; border-style:solid; border-color:#FF0000; padding: 20px;"><b>Consegna rapida?</b></p>
</body>
</html>
XYZ;
woocommerce_form_field('chosen_packing', array(
'type' => 'checkbox',
'class' => array('form-row-wide packing'),
'label' => __($variable, 'woocommerce'),
'required' => false,
), $chosen);
echo '</td></tr>';
}
我希望标签在被选中时改变,所以我尝试添加这个
add_action('woocommerce_after_checkout_billing_form', 'my_custom_checkout_field_process2');
function my_custom_checkout_field_process2() {
global $woocommerce;
// Check if set, if its not set add an error.
if (isset($_POST['chosen_packing'])){
$_POST['chosen_packing']['label'] = 'no';
}
}
但它不起作用,我不确定如何进行。 I need the label to change whenever the checkbox is checked.
【问题讨论】:
标签: javascript php wordpress woocommerce checkbox