-2
我有這樣一個功能:if function_exists unset it?
在特殊情況下,我想取消它以某種方式。我已經tride類似:
if (function_exists("custom_field")) {
unset(custom_field());
}
因爲我得到的使用未設置將無法正常工作「致命錯誤:無法使用寫上下文函數返回值」。
如何取消設置功能?我檢查了runkit_function_remove
(不知道這是否可以解決我的問題),但需要安裝PECL,我的主機不會爲我安裝。
有什麼建議嗎?
編輯:
我會用更多的代碼更新(與WordPress和woocommerce工作):
我展示這樣一個複選框:
add_action('woocommerce_after_order_notes', 'my_custom_checkout_field1');
function my_custom_checkout_field1($checkout22) {
echo '<div id="my-new-field"><h3>'.__('Homedelivery:').'</h3>';
woocommerce_form_field('Homedelivery', array(
'type' => 'checkbox',
'class' => array('input-checkbox'),
'label' => __('Message here.'),
'required' => false,
), $checkout22->get_value('my_checkbox'));
echo '</div>';
}
add_action('woocommerce_checkout_process', 'my_custom_checkout_field_process1');
function my_custom_checkout_field_process1() {
global $woocommerce;
// Check if set, if its not set add an error.
if (!$_POST['my_checkbox']) {
//$woocommerce->add_error(__('Please agree to my checkbox.'));
$_POST['my_checkbox'] = "Customer wants to be home when package is delivered.";
} else {
$_POST['my_checkbox'] = "Customers sais its ok the leave the package outside the door.";
}
}
add_action('woocommerce_checkout_update_order_meta1', 'my_custom_checkout_field_update_order_meta');
function my_custom_checkout_field_update_order_meta1($order_id) {
if ($_POST['my_checkbox']) update_post_meta($order_id, 'My Checkbox', esc_attr($_POST['my_checkbox']));
}
我想這個複選框只當選擇'local_deliver'時可見:
function payment_gateway_disable_country($available_gateways) {
global $woocommerce;
$packages = $woocommerce->shipping->get_packages();
foreach ($packages as $i => $package) {
$chosen_method = isset($woocommerce->session->chosen_shipping_methods[ $i ]) ?
$woocommerce->session->chosen_shipping_methods[ $i ] : '';
// hämta i kyrkhult
if ('local_pickup' == $chosen_method) {
global $woocommerce;
foreach ($woocommerce->cart->cart_contents as $key => $values) {
if($values['product_id'] && get_field('farskvara',$values['product_id'])){
unset($available_gateways['cod']);
break;
} else {
unset($available_gateways['cod']);
}
}
} elseif ('flat_rate' == $chosen_method) {
global $woocommerce;
foreach ($woocommerce->cart->cart_contents as $key => $values) {
if($values['product_id'] && get_field('farskvara',$values['product_id'])){
unset($available_gateways['cheque']);
break;
} else {
unset($available_gateways['cheque']);
}
}
} elseif ('local_delivery' == $chosen_method) {
global $woocommerce;
foreach ($woocommerce->cart->cart_contents as $key => $values) {
if($values['product_id'] && get_field('farskvara',$values['product_id'])){
unset($available_gateways['cheque']);
break;
} else {
unset($available_gateways['cheque']);
}
}
}
}
return $available_gateways;
}
add_filter(
'woocommerce_available_payment_gateways',
'payment_gateway_disable_country'
);
這怎麼可能固定?
你不能。只是不包括它開始。 – AbraCadaver 2014-09-02 21:31:24
爲什麼你需要這樣的東西?如果遇到名稱衝突,請考慮使用[namespace](http://php.net/manual/en/language.namespaces.php)。 – 2014-09-02 21:32:00
無論你想要解決什麼問題,都可以通過其他方式解決。 – Jon 2014-09-02 21:32:11