• bennyman

    (@bennyman)


    Help me with code php in my own automatically converter currency..
    In cart i have ZERO all price of products ((
    SEE PICTURE
    MY code (function.php):

    // SHOW fields
    add_action( 'woocommerce_checkout_update_order_meta', 'update_meta_data_with_new_currency' );
    add_action ('woocommerce_product_options_general_product_data', 'woo_add_custom_general_fields');
    
    // Exchange rates
    add_options_page('Exchange rates', 'Exchange rate', 'manage_options', 'functions','global_custom_options');
    function global_custom_options(){
    global $post, $woocommerce;
    ?>
        <div class="wrap">
            <h2>Exchange rates</h2>
            <form method="post" action="options.php">
                <?php wp_nonce_field('update-options') ?>
                <p><strong>Rate of USD:</strong><br />
                    <input type="text" name="kursd" size="45" value="<?php echo get_option('kursd'); ?>" />
                </p>
                <p><strong>Rate of EUR:</strong><br />
                    <input type="text" name="kurse" size="45" value="<?php echo get_option('kurse'); ?>" />
                </p>
                <p><strong>Rate of RUR:</strong><br />
                    <input type="text" name="kursr" size="45" value="<?php echo get_option('kursr'); ?>" />
                </p>
                <p><input type="submit" name="Submit" value="Save" /></p>
                <input type="hidden" name="action" value="update" />
                <input type="hidden" name="page_options" value="kursd,kurse,kursr" />
            </form>
        </div>
    <?php
    }
    function woo_add_custom_general_fields() {
    
    global $woocommerce, $post;
    echo '<div class="options_group">';
    woocommerce_wp_select(
    array(
        'id'      => 'selectov',
        'label'   => __( 'Exchange Rate', 'woocommerce' ),
        'options' => array(
            'one'   => __( 'BYR', 'woocommerce' ),
            'two'   => __( 'USD', 'woocommerce' ),
            'three' => __( 'EUR', 'woocommerce' ),
            'four' => __( 'RUR', 'woocommerce' ),
            )
        )
    );
      echo '</div>';
    }
    
    //**
    
    // Save fields
    add_action ('woocommerce_process_product_meta', 'woo_add_custom_general_fields_save');
    function woo_add_custom_general_fields_save( $post_id ){
        // Select
        $woocommerce_select = $_POST['selectov'];
        if( !empty( $woocommerce_select ) )
            update_post_meta( $post_id, 'selectov', esc_attr( $woocommerce_select ) );
    }
    
    function get_price() {
        return apply_filters( 'woocommerce_get_price', $this->price, $this );
    }
    
    add_filter('woocommerce_get_price','change_price', 10, 2);
    add_filter('woocommerce_get_regular_price','change_price', 10, 2);
    add_filter('woocommerce_get_sale_price','change_price', 10, 2);
    
    function change_price($price, $product){
    	global $post,$valut,$woocommerce;
    	$valut = get_post_meta( get_the_ID(), 'selectov', true );
         if ($valut == 'two'){
        $mnog = get_option('kursd');
        $new_price = $price*$mnog;
    	} elseif ($valut == 'three'){
        $mnog= get_option('kurse');
        $new_price = $price*$mnog;
        } elseif ($valut == 'four'){
        $mnog= get_option('kursr');
        $new_price = $price*$mnog;
        }
        return $new_price;
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter bennyman

    (@bennyman)

    Help with this code …((

    function change_price($price, $product){
    	global $post,$valut,$woocommerce;
    	$valut = get_post_meta( get_the_ID(), 'selectov', true );
         if ($valut == 'two'){
        $mnog = get_option('kursd');
        $new_price = $price*$mnog;
    	} elseif ($valut == 'three'){
        $mnog= get_option('kurse');
        $new_price = $price*$mnog;
        } elseif ($valut == 'four'){
        $mnog= get_option('kursr');
        $new_price = $price*$mnog;
        }
        return $new_price;
    }
    Thread Starter bennyman

    (@bennyman)

    help please!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘HOT! Woocommerce change price currency converter I made with 3 exchange rates’ is closed to new replies.