Created
October 23, 2018 12:13
-
-
Save VictorHugoBatista/3de7ccc404ada6921e64e3e3b3c908b3 to your computer and use it in GitHub Desktop.
Adiciona custom fields ao woocommerce sem ACF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Caggera os campos nas opções de preço do woocommerce. | |
// https://rudrastyh.com/woocommerce/product-data-metabox.html | |
// https://stackoverflow.com/questions/43700927/display-and-save-a-custom-field-in-product-variations-options-edit-page | |
add_action('woocommerce_product_options_pricing', function() { | |
global $woocommerce, $post; | |
$price_monthly = get_post_meta( $post->ID, 'price-monthly', true ); | |
woocommerce_wp_text_input([ | |
'id' => 'price-monthly', | |
'label' => 'Preço mensal', | |
'data_type' => 'price', | |
], $price_monthly ? $price_monthly : ''); | |
$price_monthly_promotional = get_post_meta( $post->ID, 'price-monthly-promotional', true ); | |
woocommerce_wp_text_input([ | |
'id' => 'price-monthly-promotional', | |
'label' => 'Preço mensal promocional', | |
'data_type' => 'price', | |
], $price_monthly_promotional ? $price_monthly_promotional : ''); | |
}); | |
// Salva os valores dos campos acima na postmeta. | |
add_action('woocommerce_process_product_meta', function($post_id) { | |
$price_monthly = $_POST['price-monthly']; | |
if (isset($price_monthly)) { | |
update_post_meta($post_id, 'price-monthly', esc_attr($price_monthly)); | |
} | |
$price_monthly_promotional = $_POST['price-monthly-promotional']; | |
if (isset($price_monthly_promotional)) { | |
update_post_meta($post_id, 'price-monthly-promotional', esc_attr($price_monthly_promotional)); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment