Search
 
SCRIPT & CODE EXAMPLE
 

PHP

Add Custom Field to woocommerce Subscriptions

// Showing custom fields on admin product settings "general" tab
add_action('woocommerce_product_options_general_product_data', 'add_admin_product_custom_fields', 10, 3);
function add_admin_product_custom_fields() {
    global $post;
    
    echo '<div class="product_custom_field show_if_simple show_if_subscription">';
    
    woocommerce_wp_text_input( array(
        'id'            => 'my_text_field',
        'name'          => 'my_text_field',
        'label'         => __('Some label', 'woocommerce'),
    ) );
    
    echo '</div>';
}

// Saving custom fields values from admin product settings
add_action('woocommerce_admin_process_product_object', 'save_admin_product_custom_fields_values');
function save_admin_product_custom_fields_values( $product ) {
    if ( isset($_POST['my_text_field']) ) {
        $product->update_meta_data( 'my_text_field', sanitize_text_field($_POST['my_text_field']) );
    }
}
Comment

PREVIOUS NEXT
Code Example
Php :: string to lowercase accentuation hyphenated 
Php :: Alternatives to chmod 775 or 664 
Php :: placeholder for select php 
Php :: how convert the string to int in laravel function event 
Php :: laravel dingo api response 
Php :: csv import in laravel 
Php :: redirecionar tienda agregar carrito woocommerce 
Php :: Export database to sql dump in php 
Php :: restrict_manage_posts hook 
Php :: validation.required laravel 
Php :: PHP strnatcasecmp — Case insensitive string comparisons using a "natural order" algorithm 
Php :: laravel defining relationship 
Php :: nested array in laravel 
Php :: count vs sizeof php 
Php :: Protect Your Site from Malicious Requests 
Php :: unable to composer require apidoc yii2 
Php :: pass variable in laravel ancher tag laravel 8 
Php :: alert in php after header location 
Php :: Attempt to read property "headers" on string 
Php :: wpconfig wp debug 
Php :: implode remove empty php 
Php :: php helper to get day from 0-6 
Php :: how to remove public folder from url in laravel 8 
Php :: create json file in php and write n php 
Php :: laravel import csv 
Php :: convert any date to db date in suitecrm 
Php :: Obtener rol de usuario registrado en WordPress 
Php :: how to execute a php script from the command line? 
Php :: replace class 
Php :: @parent, @include, @show blade in laravel 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =