Last active
June 5, 2019 08:26
-
-
Save eto4detak/07354cc161668f9cf53618f821172eb9 to your computer and use it in GitHub Desktop.
woo php code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/*======================================================== | |
* add field woo | |
========================================================*/ | |
add_action('woocommerce_product_options_general_product_data', 'divie_woo_add_custom_fields_euro'); | |
function divie_woo_add_custom_fields_euro() | |
{ | |
global $product, $post; | |
if (is_product() && $product->is_type('grouped')) | |
return ; | |
echo '<div class="options_group">'; | |
// цифровое поле | |
woocommerce_wp_text_input(array( | |
'id' => '_euro_rate', | |
'label' => __('Цена в евро', 'woocommerce'), | |
'placeholder' => '', | |
'description' => '', | |
'type' => 'number', | |
'custom_attributes' => array( | |
'step' => 'any', | |
'min' => '0', | |
), | |
)); | |
echo '</div>'; | |
echo '<div class="options_group">'; | |
woocommerce_wp_checkbox( | |
array( | |
'id' => '_is_period_discount', | |
'label' => __('Не применять скидку для периода на товар', 'woocommerce' ), | |
'description' => __( 'Check me!', 'woocommerce' ), | |
) | |
); | |
echo '</div>'; | |
} | |
add_action('woocommerce_process_product_meta', 'product_custom_fields_save'); | |
function product_custom_fields_save($post_id){ | |
// Custom Product Text Field | |
$_is_period_discount = isset( $_POST['_is_period_discount'] ) ? 'yes' : 'no'; | |
update_post_meta($post_id, '_is_period_discount', esc_attr( $_is_period_discount )); | |
} | |
//сохранение поля euro | |
add_action('woocommerce_process_product_meta', 'divie_woo_custom_fields_save_euro', 10); | |
function divie_woo_custom_fields_save_euro($post_id) | |
{ | |
// Сохранение цифрового поля | |
$woocommerce_number_field = $_POST['_euro_rate']; | |
if (!empty($woocommerce_number_field)) { | |
update_post_meta($post_id, '_euro_rate', esc_attr($woocommerce_number_field)); | |
} else { | |
update_post_meta($post_id, '_euro_rate', ''); | |
} | |
} | |
//admin settings page | |
add_action('admin_menu', 'divie_register_wc_submenu_page_url_euro', 999); | |
function divie_register_wc_submenu_page_url_euro() | |
{ | |
add_submenu_page('edit.php?post_type=product', 'Euro rate', 'Euro rate', 'manage_options', 'euro-rate', 'divie_subpage_euro_rate'); | |
} | |
function divie_subpage_euro_rate() | |
{ | |
if (isset($_POST['update_rate_euro'])) { | |
divie_upadte_rate_euro(); | |
} | |
if (isset($_POST['update_all_euro_product'])) { | |
divie_all_products_woo_edit(); | |
} | |
$actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; | |
?> | |
<div class="wrap"> | |
<form action="<?php echo $actual_link; ?>" method="POST"> | |
<input type="hidden" name="update_rate_euro" value="1"> | |
<?php | |
settings_fields('divie_opt_gr'); | |
do_settings_sections('divie_page1'); | |
echo '<span style="margin-right:20px;line-height: 2em;">Курс евро : <span>' . get_option('divie_euro_rate') . '</span></span>'; | |
echo '<input type="submit" name="submit" id="submit" class="button button-primary" value="Обновить курс евро">'; | |
?> | |
</form> | |
<div style="margin:20px"></div> | |
<form action="<?php echo $actual_link; ?>" method="POST"> | |
<input type="hidden" name="update_all_euro_product" value="1"> | |
<?php | |
echo '<input type="submit" name="submit" id="submit" class="button button-primary" value="Обновить цены с евро">'; | |
?> | |
</form> | |
</div> | |
<?php | |
} | |
add_action('admin_init', 'divie_cars_settings_page_euro'); | |
function divie_cars_settings_page_euro() | |
{ | |
register_setting('divie_opt_gr', 'divie_cars_templ', 'divie_sanitize_clb_eur'); | |
add_settings_section('section_id', __('Euro rate', 'divi'), '', 'divie_page1'); | |
} | |
function divie_sanitize_clb_eur($options) | |
{ | |
return $options; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment