Last active
April 17, 2020 12:56
-
-
Save Retter241/19ffc21144b50040892fcc9b9d38f0bc to your computer and use it in GitHub Desktop.
Wordpress
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
/* | |
* Создание доп полей сео для атрибутов | |
* https://pippinsplugins.com/adding-custom-meta-fields-to-taxonomies/ | |
*/ | |
/******************** Seo Title ************************/ | |
// Add term page | |
function pippin_taxonomy_add_new_meta_field() { | |
// this will add the custom meta field to the add new term page | |
?> | |
<div class="form-field"> | |
<label for="term_meta[custom_term_meta]">Seo title</label> | |
<input type="text" name="term_meta[custom_seo_title]" id="term_meta[custom_seo_title]" value=""> | |
<p class="description"><?php _e( 'Статичный','pippin' ); ?></p> | |
</div> | |
<?php | |
} | |
// Edit term page | |
function pippin_taxonomy_edit_meta_field($term) { | |
// put the term ID into a variable | |
$t_id = $term->term_id; | |
//var_dump($term); | |
// retrieve the existing value(s) for this meta field. This returns an array | |
$term_meta = get_option( "taxonomy_$t_id" ); ?> | |
<tr class="form-field"> | |
<th scope="row" valign="top"><label for="term_meta[custom_seo_title]">Seo title</label></th> | |
<td> | |
<input type="text" name="term_meta[custom_seo_title]" id="term_meta[custom_seo_title]" value="<?php echo esc_attr( $term_meta['custom_seo_title'] ) ? esc_attr( $term_meta['custom_seo_title'] ) : ''; ?>"> | |
<p class="description"><?php _e( 'Статичный','pippin' ); ?></p> | |
</td> | |
</tr> | |
<?php | |
} | |
/******************** Seo Description ************************/ | |
// Add term page | |
function desc_pippin_taxonomy_add_new_meta_field() { | |
// this will add the custom meta field to the add new term page | |
?> | |
<div class="form-field"> | |
<label for="term_meta[custom_term_meta]">Seo Description</label> | |
<!-- <input type="text" name="term_meta[custom_seo_description]" id="term_meta[custom_seo_description]" value="">--> | |
<textarea name="term_meta[custom_seo_description]" id="term_meta[custom_seo_description]" rows="5" cols="40"></textarea> | |
<p class="description"><?php _e( 'Статичный','pippin' ); ?></p> | |
</div> | |
<?php | |
} | |
// Edit term page | |
function desc_pippin_taxonomy_edit_meta_field($term) { | |
// put the term ID into a variable | |
$t_id = $term->term_id; | |
//var_dump($term); | |
// retrieve the existing value(s) for this meta field. This returns an array | |
$term_meta = get_option( "taxonomy_$t_id" ); ?> | |
<tr class="form-field"> | |
<th scope="row" valign="top"><label for="term_meta[custom_seo_description]">Seo Description</label></th> | |
<td> | |
<!-- <input type="text" name="term_meta[custom_seo_description]" id="term_meta[custom_seo_description]" value="--><?php //echo esc_attr( $term_meta['custom_seo_description'] ) ? esc_attr( $term_meta['custom_seo_description'] ) : ''; ?><!--">--> | |
<textarea name="term_meta[custom_seo_description]" id="term_meta[custom_seo_description]" rows="5" cols="40"><?php echo esc_attr( $term_meta['custom_seo_description'] ) ? esc_attr( $term_meta['custom_seo_description'] ) : ''; ?></textarea> | |
<p class="description"><?php _e( 'Статичный','pippin' ); ?></p> | |
</td> | |
</tr> | |
<?php | |
} | |
// Save extra taxonomy fields callback function. | |
function save_taxonomy_custom_meta( $term_id ) { | |
if ( isset( $_POST['term_meta'] ) ) { | |
$t_id = $term_id; | |
$term_meta = get_option( "taxonomy_$t_id" ); | |
$cat_keys = array_keys( $_POST['term_meta'] ); | |
foreach ( $cat_keys as $key ) { | |
if ( isset ( $_POST['term_meta'][$key] ) ) { | |
$term_meta[$key] = $_POST['term_meta'][$key]; | |
} | |
} | |
// Save the option array. | |
update_option( "taxonomy_$t_id", $term_meta ); | |
} | |
} | |
//Инициируем для атрибутов вручную | |
$attributes = array(/*'czvet','for','razmer',*/'sostav'); | |
foreach ($attributes as $attribute){ | |
add_action( 'pa_'.$attribute.'_add_form_fields', 'pippin_taxonomy_add_new_meta_field', 10, 2 ); | |
add_action( 'pa_'.$attribute.'_edit_form_fields', 'pippin_taxonomy_edit_meta_field', 10, 2 ); | |
add_action( 'pa_'.$attribute.'_add_form_fields', 'desc_pippin_taxonomy_add_new_meta_field', 10, 2 ); | |
add_action( 'pa_'.$attribute.'_edit_form_fields', 'desc_pippin_taxonomy_edit_meta_field', 10, 2 ); | |
add_action( 'edited_pa_'.$attribute, 'save_taxonomy_custom_meta', 10, 2 ); | |
add_action( 'create_pa_'.$attribute, 'save_taxonomy_custom_meta', 10, 2 ); | |
} |
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
/* | |
* Добавление поля экспресс доставка у товара | |
* https://wpruse.ru/woocommerce/custom-fields-in-products/ | |
*/ | |
add_action( 'woocommerce_product_options_general_product_data', 'art_woo_add_custom_fields' ); | |
function art_woo_add_custom_fields() { | |
global $product, $post; | |
echo '<div class="options_group">';// Группировка полей | |
// Чекбокс | |
woocommerce_wp_checkbox( array( | |
'id' => '_express_checkbox', | |
'wrapper_class' => 'show_if_simple', | |
'label' => 'Экспресс доставка', | |
'description' => '', | |
) ); | |
echo '</div>'; | |
} | |
add_action( 'woocommerce_process_product_meta', 'art_woo_custom_fields_save', 10 ); | |
function art_woo_custom_fields_save( $post_id ) { | |
$woocommerce_checkbox = isset( $_POST['_express_checkbox'] ) ? 'yes' : 'no'; | |
update_post_meta( $post_id, '_express_checkbox', $woocommerce_checkbox ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment