• I have a couple of custom functions and I do not know what PROPER php code I need to have in order to get them to echo on two main template files:

    admin-new-order.php and customer-processing-order.php files…

    My Functions.php file from my child theme:

    add_filter( 'woocommerce_shipping_fields', 'wc_npr_filter_company', 10, 1 );
    
    function wc_npr_filter_company( $address_fields ) {
    $address_fields['shipping_company']['required'] = true;
    return $address_fields;
    }
    
    /**
     * Add the field to the checkout**/
    
    add_action('woocommerce_after_order_notes', 'social_good_field');
    
    function social_good_field( $checkout ) {
    
        woocommerce_form_field( 'social good', array(
            'type'          => 'select',
            'class'         => array('my-field-class form-row-wide'),
            'label'         => __('Select Charity To Donate Part of Sale'),
    		'clear' => false,
    		'options' => array(
    		'ASPCA' => __( 'ASPCA', 'woocommerce' ),
    		'PetsMart' => __( 'PetsMart Charities', 'woocommerce'),
    		'The Humane Society' => __( 'The Humane Society', 'woocommerce'),
    		'he Broward Humane Society' => __( 'The Broward Humane Society', 'woocommerce'),
    		'American Humane Association' => __( 'American Humane Association', 'woocommerce'),
    		'Other' => __( 'Other', 'woocommerce'),
    		),
            ),
    
    		$checkout->get_value( 'social good' ));
    }	 
    
    /**
     * Update the order meta with field value
     **/
    add_action('woocommerce_checkout_update_order_meta', 'social_good_field_update_order_meta');
    
    function social_good_field_update_order_meta( $order_id ) {
        if ($_POST['social_good']) update_post_meta( $order_id, 'My Social', esc_attr($_POST['social_good']));
    }
    
    /**
     * Add the field to the checkout
     **/
    add_action('woocommerce_after_order_notes', 'my_custom_checkout_field');
    
    function my_custom_checkout_field( $checkout ) {
    
        echo '<div id="my_custom_checkout_field"><h2>'.__('Other Charity').'</h2>';
    
        woocommerce_form_field( 'my_field_name', array(
            'type'          => 'text',
            'class'         => array('my-field-class form-row-wide'),
            'label'         => __('Type in the name and email address of the special charity you want a part of the sale to go to'),
            'placeholder'       => __('charity name and email'),
            ), $checkout->get_value( 'my_field_name' ));
    
        echo '</div>';
    
    }
    
    /**
     * Update the order meta with field value
     **/
    add_action('woocommerce_checkout_update_order_meta', 'my_custom_checkout_field_update_order_meta');
    
    function my_custom_checkout_field_update_order_meta( $order_id ) {
        if ($_POST['my_field_name']) update_post_meta( $order_id, 'My Social Field', esc_attr($_POST['my_field_name']));
    }
    
    /**
     * Process the checkout
     **/
    add_action('woocommerce_checkout_process', 'my_custom_checkout_field_process');
    
    function my_custom_checkout_field_process() {
        global $woocommerce;
    
        // Check if set, if its not set add an error.
        if ($_POST['social_good'] == 'Other' and !$_POST['my_field_name'])
             $woocommerce->add_error( __('Please enter charity and email into text .') );
    }

    I tried these ideas and this did not work:

    <?php echo get_post_meta( get_the_ID(), ‘My Social Field’, true ); ?> <?php echo get_post_meta($post->ID, ‘My Social Field’, true); ?>

    some help over here….

    https://www.ads-software.com/plugins/woocommerce/

  • The topic ‘[plugin: Woocommerce] ECHO and custom fields help needed…’ is closed to new replies.