Woocommerce a vlastni cena

Zvolené téma obsahuje celkem 1 odpověď. Do diskuze (1 účastník) se naposledy zapojil uživatel  endwin a poslední změna je stará 8 let, 2 měsíce.

Aktuálně jsou na stránce zobrazeny 2 příspěvky - 1. až 2. (z celkem 2)
  • Autor
    Příspěvky
  • #26432

    endwin
    Participant

    Dobrý den.
    Mam nahoyen Woocommerce a potreboval jsem na nem udelat pro zmenu jayzka na EN, zmena ceny na Eura.
    Nasel jsem nejake postupy pro vytvoreni vlastni kolonky ceny v tabulce produktu, to funguje…
    Ale kdyz to volam, tak se mi nacita pro simple produkty, pro variation produktu, ale ma problem u zahadneho typu produktu variable… Prikladam predefinovane funkce:

    
    
    add_filter( 'woocommerce_get_price', 'woocommerce_get_price_eur', 100, 2);
    function woocommerce_get_price_eur( $price, $product ){
        $lang = explode('_', get_locale());
        $lang = $lang[0];
        if( $lang == 'en' ){                                
            $price = get_my_eur_price($product);
        }                      
          return $price;
    }
    
    function get_my_eur_price( $product ){
            static $products = array();
            $p_id = 0;
    
            //init product ID
            if (!empty($product->variation_id)) {
                $p_id = $product->variation_id;
            } else {
                $p_id = $product->id;   
            }   
        return get_post_meta( $p_id, '_regular_price_eur', true );
    }
    
    add_filter( 'woocommerce_currency', 'get_my_currency' );
    
    function get_my_currency( $currency ){
        $lang = explode('_', get_locale());
        $lang = $lang[0];
        if( $lang == 'en' ){                                
            $currency = 'EUR';
        }               
        return $currency;
    }
    
    add_filter( 'woocommerce_currency_symbol', 'get_my_currency_symbol' );
    
    function get_my_currency_symbol( $currency_symbol ){
        $lang = explode('_', get_locale());
        $lang = $lang[0];
        if( $lang == 'en' ){                                
            $currency_symbol = '€';    //     €
        }      */                           
        return $currency_symbol;
    } 
    

    Poznate tam nekdo nejakou chybu?
    Vim ze to neni aktualne pro sales price definovane…
    Cena se nacte do pole ktere je u produktu ve form, ale nenacte se price_html. Tu to vraci prazdnou…

    Predem dekuji za vsechny reakce.

    #26433

    endwin
    Participant

    jo a tady je kdyztak kod na inputy kdyby to nekdo chtel testnout…

    
     
     // Add Variation Settings
    add_action( 'woocommerce_product_after_variable_attributes', 'variation_settings_fields', 10, 3 );
    // Save Variation Settings
    add_action( 'woocommerce_save_product_variation', 'save_variation_settings_fields', 10, 1 );
    /**
     * Create new fields for variations
     *
    */
    function variation_settings_fields( $loop, $variation_data, $variation ) {
    	// Number Field
    	woocommerce_wp_text_input( 
    		array( 
    			'id'          => '_regular_price_eur[' . $variation->ID . ']', 
    			'label'       => __( 'Regular price in EUR', 'woocommerce' ), 
    			'desc_tip'    => 'true',          
          'class'       => 'short',
    			'description' => __( 'Enter regular price .', 'woocommerce' ),
    			'value'       => get_post_meta( $variation->ID, '_regular_price_eur', true ),
    			'custom_attributes' => array(
    							'step' 	=> 'any',
    							'min'	=> '0'
    						) 
    		)
    	);
    	// Number Field
    	woocommerce_wp_text_input( 
    		array( 
    			'id'          => '_sales_price_eur[' . $variation->ID . ']', 
    			'label'       => __( 'Sales price in EUR', 'woocommerce' ), 
    			'desc_tip'    => 'true',                    
          'class'       => 'short',
    			'description' => __( 'Enter the custom number here.', 'woocommerce' ),
    			'value'       => get_post_meta( $variation->ID, '_sales_price_eur', true ),
    			'custom_attributes' => array(
    							'step' 	=> 'any',
    							'min'	=> '0'
    						) 
    		)
    	);
    }
    /**
     * Save new fields for variations
     *
    */
    function save_variation_settings_fields( $post_id ) {
    	// Number Field
    	$number_field = $_POST['_regular_price_eur'][ $post_id ];
    	if( ! empty( $number_field ) ) {
    		update_post_meta( $post_id, '_regular_price_eur', esc_attr( $number_field ) );
    	}
    	
    	// Number Field
    	$number_field = $_POST['_sales_price_eur'][ $post_id ];
    	if( ! empty( $number_field ) ) {
    		update_post_meta( $post_id, '_sales_price_eur', esc_attr( $number_field ) );
    	}
    } 
    
           
    /**
     * Create new fields for single
     *
    */ 
    add_action( 'woocommerce_product_options_pricing', 'single_settings_fields' ); 
    // Save Variation Settings
    add_action( 'woocommerce_process_product_meta_simple', 'save_single_settings_fields', 10, 1 );
    
    function single_settings_fields( $product ) {
    	// Number Field
    	woocommerce_wp_text_input( 
    		array(    
    			'id'          => '_regular_price_eur', 
          'class'       => 'short',
    			'label'       => __( 'Regular price in EUR', 'woocommerce' ), 
    			'desc_tip'    => 'true',
    			'description' => __( 'Enter regular price .', 'woocommerce' ), 
    			'value'       => get_post_meta( $_REQUEST['post'], '_regular_price_eur', true ),
    			'custom_attributes' => array(
    							'step' 	=> 'any',
    							'min'	=> '0'
    						) 
    		)
    	);
    	// Number Field
    	woocommerce_wp_text_input( 
    		array( 
    			'id'          => '_sales_price_eur', 
          'class'       => 'short',
    			'label'       => __( 'Sales price in EUR', 'woocommerce' ), 
    			'desc_tip'    => 'true',
    			'description' => __( 'Enter the custom number here.', 'woocommerce' ),
    			'value'       => get_post_meta( $_REQUEST['post'], '_sales_price_eur', true ),
    			'custom_attributes' => array(
    							'step' 	=> 'any',
    							'min'	=> '0'
    						) 
    		)
    	);
    }
    /**
     * Save new fields for single
     *
    */ 
    function save_single_settings_fields( $product_id ) {
    	// Number Field
    	$number_field = $_POST['_regular_price_eur'];
    	if( ! empty( $number_field ) ) {
    		update_post_meta( $product_id, '_regular_price_eur', esc_attr( $number_field ) );
    	}
    	
    	// Number Field
    	$number_field = $_POST['_sales_price_eur'];
    	if( ! empty( $number_field ) ) {
    		update_post_meta( $product_id, '_sales_price_eur', esc_attr( $number_field ) );
    	}
    } 
    
Aktuálně jsou na stránce zobrazeny 2 příspěvky - 1. až 2. (z celkem 2)

Pokud chcete odpovědět na toto téma, musíte se nejdříve přihlásit.

WordPress – novinky, návody a zajímavosti