Skip to content

Instantly share code, notes, and snippets.

@amin3d
Created September 14, 2016 11:35
Show Gist options
  • Save amin3d/e29af4a492a3faa728b3b52ee155ef69 to your computer and use it in GitHub Desktop.
Save amin3d/e29af4a492a3faa728b3b52ee155ef69 to your computer and use it in GitHub Desktop.
Iranian Tax Rate woocommerce
function add_iranian_tax_rate( $settings ) {
$updated_settings = array();
foreach ( $settings as $section ) {
if ( isset( $section['id'] ) && 'tax_options' == $section['id'] &&
isset( $section['type'] ) && 'sectionend' == $section['type'] ) {
$updated_settings[] = array(
'name' => 'میزان نرخ مالیات',
'desc_tip' => 'در این بخش می توانید نرخ مالیات را وارد نمایید',
'id' => 'woocommerce_iranian_tax_rate',
'type' => 'text',
'css' => 'min-width:300px;',
'std' => '9', // WC < 2.0
'default' => '9', // WC >= 2.0
'desc' => 'در این بخش می توانید نرخ مالیات را وارد نمایید',
);
}
$updated_settings[] = $section;
}
return $updated_settings;
}
add_action('woocommerce_review_order_after_cart_contents','show_iranian_tax_rate_in_checkout');
function show_iranian_tax_rate_in_checkout(){
$total = WC()->cart->cart_contents_total;
$rate = get_option('woocommerce_iranian_tax_rate',true);
$tax= number_format(($total*$rate)/100);
echo '<tr><th>میزان مالیات</th><th>'.$tax.' تومان</th>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment