Я думаю, что это очень легко исправить - но каждый раз, когда я вставляю хук - я получаю критическую ошибку WordPress, и я не знаю, что я делаю неправильно - новичок в Hooks, поэтому, пожалуйста, прости меня.
Я пытаюсь просто напечатать значение, которое я сохранил в бэкэнде, чтобы вывести его на передний конец.
Заранее спасибо!
(этот код в функции. php)
//Custom Colour Text Box
add_action( 'woocommerce_product_options_inventory_product_data', 'wc_custom_add_custom_fields' );
function wc_custom_add_custom_fields() {
// Print a custom text field
woocommerce_wp_text_input( array(
'id' => '_custom_text_field',
'label' => 'Product Colour',
'description' => 'This is where you put the colour of the product in.',
'desc_tip' => 'true',
'placeholder' => 'Custom Colour'
) );
}
add_action( 'woocommerce_process_product_meta', 'wc_custom_save_custom_fields' );
function wc_custom_save_custom_fields( $post_id ) {
if ( ! empty( $_POST['_custom_text_field'] ) ) {
update_post_meta( $post_id, '_custom_text_field', esc_attr( $_POST['_custom_text_field'] ) );
}
}
add_action( 'woocommerce_after_shop_loop_item_title', 'custom_field_display_below_title', 2 );
function custom_field_display_below_title(){
global $product;
// Get the custom field value
$custom_field = get_post_meta( $product->get_id(), '_custom_product_text_field', true );
// Display
if( ! empty($custom_field) ){
echo '<p class="my-custom-field">'.$custom_field.'</p>';
}
}
/**** Display on the Product Page ***/
add_action( 'woocommerce_single_product_summary', 'custom_text', 9 );
function custom_text() {
print '<p class="my-custom-field"></p>';
}