How to set new price rule depend currenccy
I need new price rule depend currency.I am new at learning WooCommerce development and this feature is sample for me to learn it.
The question is simple : I have a input field which is number type under product tabs on settings page and I will enter US dollar value against Turkish Liras.
For example: 8.20
It means 1 US Dollar is equal to 8.20 Turkish Liras.
When I click save button, my custom code will change all products’ prices.If US dollar increase, also Product Price will increase or the rule exist for opposite scenerio.
The formule: ( Current Price X New Value ) / Current Value
My main problem is I cant set/change all product prices with save button.How can I do it?
Here is my code snippets about settings page from theme’s function.php:
/*------------------------------------*
*/
add_filter( 'woocommerce_get_sections_products' , 'new_price_based_currency_add_settings_tab' );
function new_price_based_currency_add_settings_tab( $settings_tab ){
$settings_tab['new_price_based_currency_notices'] = __( 'New Price based Currency Notices' );
return $settings_tab;
}
add_filter( 'woocommerce_get_settings_products' , 'new_price_based_currency_get_settings' , 10, 2 );
function new_price_based_currency_get_settings( $settings, $current_section ) {
$custom_settings = array();
if( 'new_price_based_currency_notices' == $current_section ) {
$custom_settings = array(
array(
'name' => __( 'New Price based Currency Notices' ),
'type' => 'title',
'desc' => __( 'When you change the currency value, your all product prices will be changed.For example, if you enter new value, new price will be calculated with "( Current Price X New Value ) / Current Value' ),
'id' => 'new_price_based_currency'
),
array(
'name' => __( 'US Dollar value based on Turkish Lira' ),
'type' => 'number',
'min' => '0',
'step' => '0.01',
'append' => '$',
'desc' => __( 'You must write US Dollar value against Turkish Lira here.For example, "8.42" . It means 8.42 Turkish Liras is equal to 1 US Dollar.'),
'desc_tip' => true,
'id' => 'dollar_value'
),
array( 'type' => 'sectionend', 'id' => 'new_price_based_currency' ),
);
return $custom_settings;
} else {
return $settings;
}
}
When I enter new value to the input field, I want to change all prices automatically depend new currency value.
Leave an answer