Jump to content

Colocando preço do produto variável dentro do DROPDOWN


403 - Forbiddeen
 Share

Recommended Posts

  • Fundador

Colocando preço do produto variável dentro do DROPDOWN


Um código simples para ajuda-lo a expor o preço do seus produtos variáveis dentro na hora do cliente selecionar. Por padrão não é exibido! Para exibir basta editar o arquivo FUNCTIONS.PHP do seu tema e colar o seguinte código no final; //Add prices to variations add_filter( 'woocommerce_variation_option_name', 'display_price_in_variation_option_name' ); function display_price_in_variation_option_name( $term ) { global $wpdb, $product; $result = $wpdb->get_col( "SELECT slug FROM {$wpdb->prefix}terms WHERE name = '$term'" ); $term_slug = ( !empty( $result ) ) ? $result[0] : $term; $query = "SELECT postmeta.post_id AS product_id FROM {$wpdb->prefix}postmeta AS postmeta LEFT JOIN {$wpdb->prefix}posts AS products ON ( products.ID = postmeta.post_id ) WHERE postmeta.meta_key LIKE 'attribute_%' AND postmeta.meta_value = '$term_slug' AND products.post_parent = $product->id"; $variation_id = $wpdb->get_col( $query ); $parent = wp_get_post_parent_id( $variation_id[0] ); if ( $parent > 0 ) { $_product = new WC_Product_Variation( $variation_id[0] ); $itemPrice = strip_tags (woocommerce_price( $_product->get_price() )); //this is where you can actually customize how the price is displayed return $term . ' (' . $itemPrice . ')'; } return $term; } O código é de autoria do Derek, achei no google nesse blog. Mesmo sendo de 2013, funcionou direitinho!

 

Antes de perguntar, visite a Wiki GGames | Quer GCoins? Junte-se ao meu Clube

Junta-se ao Telegram Oficial do GGames, lá pode falar de tudo! | Clique aqui

 

Link to comment
Share on other sites

  • 16.9k
  • 9.6k
  • 804
  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share



×
×
  • Create New...

pc jenkins GIF by South Park

AdBlock extension detected!

GGames is maintained by advertisements for our visitors.

Please disable your browser's AdBlock Extension first, in order to use our Forum.

Rest assured, our ads will not disturb your browsing and reading.

I've Dissable