Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #15563

    Hello Kriesi team!

    since I m quite new on php and struggling a bit but really enjoying it so far, would it be hard to do some corrections on my attached functions.php ?

    <?php
    ##################################################################
    # AVIA FRAMEWORK by Kriesi

    # this include calls a file that automatically includes all
    # the files within the folder framework and therefore makes
    # all functions and classes available for later use

    add_theme_support('avia_mega_menu');
    require_once( 'framework/avia_framework.php' );

    ##################################################################

    //register additional image thumbnail sizes that should be generated when user uploads an image:
    global $avia_config;

    $avia_config['imgSize']['widget'] = array('width'=>36, 'height'=>36 ); // small preview pics eg sidebar news
    $avia_config['imgSize']['small'] = array('width'=>130, 'height'=>130); // small images for small blog overview images
    $avia_config['imgSize']['related'] = array('width'=>163, 'height'=>120); // small images for related items
    $avia_config['imgSize']['page'] = array('width'=>690, 'height'=>200); // image for pages and one column portfolio
    $avia_config['imgSize']['blog'] = array('width'=>530, 'height'=>255); // image for blog posts (big)
    $avia_config['imgSize']['featured'] = array('width'=>930, 'height'=>500); // big images for fullsize pages and fullsize 2D & 3D slider
    $avia_config['imgSize']['fullsize'] = array('width'=>930, 'height'=>930, 'crop'=>false); // big images for lightbox
    $avia_config['imgSize']['aviacordion'] = array('width'=>697, 'height'=>500); // big Image for aviacordion
    $avia_config['imgSize']['slide_thumbs'] = array('width'=>210, 'height'=>100); // small preview pic for slideshow thumbs

    /*preview images for special column sizes of the dynamic template. you can remove those if you dont use them, it will save performance while uploading images and will also save ftp storage*/
    $avia_config['imgSize']['portfolio4'] = array('width'=>210, 'height'=>120); // small preview pic for default portfolio (4 columns )
    $avia_config['imgSize']['portfolio3'] = array('width'=>290, 'height'=>150); // medium preview pic for 3 column portfolio
    $avia_config['imgSize']['portfolio3_sb']= array('width'=>210, 'height'=>120); // medium preview pic for 3 column portfolio with sidebar
    $avia_config['imgSize']['portfolio2'] = array('width'=>450, 'height'=>300); // medium preview pic for 2 column portfolio and small 3d slider
    $avia_config['imgSize']['grid6'] = array('width'=>450, 'height'=>120); // half sized images when using 4 columns
    $avia_config['imgSize']['grid8'] = array('width'=>450, 'height'=>120); // two/third image
    $avia_config['imgSize']['grid9'] = array('width'=>690, 'height'=>120); // three/fourth image

    ///////

    avia_backend_add_thumbnail_size($avia_config);

    /*
    * compat mode for easier theme switching from one avia framework theme to another
    */
    add_theme_support( 'avia_post_meta_compat');

    ##################################################################
    # Frontend Stuff necessary for the theme:
    ##################################################################

    $lang = TEMPLATEPATH . '/lang';
    load_theme_textdomain('avia_framework', $lang);

    /* Register frontend javascripts: */
    /* Register frontend javascripts: */
    if(!is_admin()){
    add_action('init', 'avia_frontend_js');
    }

    function avia_frontend_js()
    {
    wp_register_script( 'avia-default', AVIA_BASE_URL.'js/avia.js', array('jquery','avia-html5-video'), 1, false );
    wp_register_script( 'avia-prettyPhoto', AVIA_BASE_URL.'js/prettyPhoto/js/jquery.prettyPhoto.js', 'jquery', "3.0.1", true);
    wp_register_script( 'avia-html5-video', AVIA_BASE_URL.'js/projekktor/projekktor.min.js', 'jquery', "1", true);
    wp_register_script( 'avia-slider', AVIA_BASE_URL.'js/aviaslider-dev.js', 'jquery', "2.5.2", true);
    wp_register_script( 'aviacordion', AVIA_BASE_URL.'js/aviacordion-dev.js', 'jquery', "1.0.0", true);
    wp_register_script( 'avia_fade_slider', AVIA_BASE_URL.'js/avia_fade_slider-dev.js', 'jquery', "1.0.0", true);
    }

    /* Activate native wordpress navigation menu and register a menu location */
    add_theme_support('nav_menus');
    $avia_config['nav_menus'] = array('avia' => 'Main Menu', 'avia2'=> 'Sub Menu');
    foreach($avia_config['nav_menus'] as $key => $value){ register_nav_menu($key, THEMENAME.' '.$value); }

    //load some frontend functions in folder include:

    require_once( 'includes/admin/register-widget-area.php' ); // register sidebar widgets for the sidebar and footer
    require_once( 'includes/admin/register-styles.php' ); // register the styles for dynamic frontend styling
    require_once( 'includes/admin/register-shortcodes.php' ); // register wordpress shortcodes
    require_once( 'includes/loop-comments.php' ); // necessary to display the comments properly
    require_once( 'includes/helper-slideshow.php' ); // holds the class that generates the 2d & 3d slideshows, as well as feature images
    require_once( 'includes/helper-templates.php' ); // holds some helper functions necessary for dynamic templates
    require_once( 'includes/admin/compat.php' ); // compatibility functions for 3rd party plugins

    //adds the woocommerce initalisation scripts that add styles and functions
    require_once( 'woocommerce-config/config.php' );

    //activate framework widgets
    register_widget( 'avia_tweetbox');
    register_widget( 'avia_newsbox' );
    //register_widget( 'avia_portfoliobox' );
    register_widget( 'avia_socialcount' );
    register_widget( 'avia_combo_widget' );
    register_widget( 'avia_partner_widget' );

    //call functions for the theme
    add_filter('the_content_more_link', 'avia_remove_more_jump_link');
    add_post_type_support('page', 'excerpt');

    //allow mp4, webm and ogv file uploads
    add_filter('upload_mimes','avia_upload_mimes');
    function avia_upload_mimes($mimes){ return array_merge($mimes, array ('mp4' => 'video/mp4', 'ogv' => 'video/ogg', 'webm' => 'video/webm')); }

    //change default thumbnail size on theme activation
    add_action('avia_backend_theme_activation', 'avia_set_thumb_size');
    function avia_set_thumb_size() {update_option( 'thumbnail_size_h', 80 ); update_option( 'thumbnail_size_w', 80 );}

    //remove post thumbnails from pages, posts and various custom post types
    if(!function_exists('avia_remove_post_thumbnails'))
    {
    add_theme_support( 'post-thumbnails' );

    add_action('posts_selection', 'avia_remove_post_thumbnails');
    add_action('init', 'avia_remove_post_thumbnails');
    add_filter('post_updated_messages','avia_remove_post_thumbnails');
    function avia_remove_post_thumbnails($msg)
    {
    global $post_type;
    $remove_when = array('post','page');

    if(is_admin())
    {
    foreach($remove_when as $remove)
    {
    if($post_type == $remove || (isset($_GET['post_type']) && $_GET['post_type'] == $remove)) { remove_theme_support( 'post-thumbnails' ); };
    }
    }

    return $msg;
    }
    }

    /*advanced title + breadcrumb function*/
    function avia_title($post = "", $_product = "", $title = "")
    {
    if(!$_product)
    {
    global $product;
    $_product = $product;
    }

    if(!$title) $title = get_the_title();

    echo "<div class='title_container'>";
    if(!is_front_page()) echo avia_breadcrumbs();
    echo '<h1 class="page-title">'.$title.'</h1>';
    if($_product && is_singular())
    {
    echo "<div class='price_container'>";
    woocommerce_template_single_price($post, $_product);
    echo "</div>";
    }
    echo "</div>";
    }

    /*wordpress 3.4 changed 404 check - this is the mod for the avia framework to operate*/
    function avia_disable_404( $query = false ) {

    global $avia_config, $wp_query;

    if(!isset($avia_config['first_query_run']) && is_front_page() && is_paged())
    {
    $wp_query->is_paged = false;
    $avia_config['first_query_run'] = true;
    add_action( 'wp', 'avia_enable_404' );
    }
    }

    function avia_enable_404() {

    global $wp_query;
    $wp_query->is_paged = true;

    }

    add_action( 'pre_get_posts', 'avia_disable_404' ,1 ,10000);

    /**
    * end of the formal code, from down below are additional edits
    */

    /**
    * order products by DATE and in DESC order aka from Newest to Oldest.
    **/

    add_filter('woocommerce_get_catalog_ordering_args', 'am_woocommerce_catalog_orderby');
    function am_woocommerce_catalog_orderby( $args ) {
    $args['orderby'] = 'date';
    $args['order'] = 'desc';
    return $args;
    }

    /**
    * This fixes the problem with the sorter> But the sorter on the right should be showing as "most recent" by default instead of alphabetically.
    **/

    function woocommerce_catalog_ordering() {
    if (!isset($_SESSION['orderby'])) $_SESSION['orderby'] = apply_filters('woocommerce_default_catalog_orderby', 'date');
    woocommerce_get_template('loop/sorting.php');
    }

    /**
    * Outputs a radio button form field
    */

    function woocommerce_form_field_radio( $key, $args, $value = '' ) {
    global $woocommerce;

    $defaults = array(
    'type' => 'radio',
    'label' => '',
    'placeholder' => '',
    'required' => false,
    'class' => array() ,
    'label_class' => array() ,
    'return' => false,
    'options' => array()
    );

    $args = wp_parse_args( $args, $defaults );

    if ( ( isset( $args['clear'] ) && $args['clear'] ) )
    $after = '<div class="clear"></div>'; else $after = '';

    $required = ( $args['required'] ) ? ' <abbr class="required" title="' . esc_attr__( 'required', 'woocommerce' ) . '">*</abbr>' : '';

    switch ( $args['type'] ) {

    case "radio" :

    $options = '';

    if ( ! empty( $args['options'] ) ) :

    foreach ( $args['options'] as $option_key => $option_text ) :

    $options .= '<input type="radio" name="' . $key . '" id="' . $key . '" value="' . $option_key . '" '. selected( $value, $option_key, false ) . 'class="select">' . $option_text .'<br />' . "rn";

    $field = '<p class="form-row ' . implode( ' ', $args['class'] ) .'" id="' . $key . '_field"><label for="' . $key . '" class="' . implode( ' ', $args['label_class'] ) .'">' . $args['label']. $required . '</label>' . $options . '</p>' . $after;

    endforeach;

    endif;

    break;

    }

    if ( $args['return'] ) return $field; else echo $field;
    }

    /**
    * Add the field to the checkout
    **/
    add_action('woocommerce_after_order_notes', 'hear_about_us_field');

    function hear_about_us_field( $checkout ) {

    echo '<div id="hear_about_us_field"><h3>'.__('How did you hear about us?').'</h3>';

    woocommerce_form_field_radio( 'hear_about_us', array(
    'type' => 'radio',
    'class' => array('here-about-us form-row-wide'),
    'label' => __(''),
    'placeholder' => __(''),
    'required' => false,
    'options' => array(

    'Internet Search' => 'Internet Search',
    'Friend' => 'Friend',
    'Flyer/Look book' => 'Flyer/Look book',
    'Magazine' => 'Magazine',
    'Press' => 'Press',
    'ROUS ILAND Showroom' => 'ROUS ILAND Showroom',
    'Other' => 'Other',
    )
    ), $checkout->get_value( 'hear_about_us' ));

    woocommerce_form_field( 'hear_about_us_other', array(
    'type' => 'text',
    'class' => array('my-field-class form-row-wide'),
    'label' => __(''),
    'placeholder' => __('Please fill in details here'),
    ), $checkout->get_value( 'hear_about_us_other' ));

    echo '</div>';

    }

    add_action('woocommerce_after_order_notes', 'newsletter_options_field');

    function newsletter_options_field( $checkout ) {

    echo '<div id="newsletter_options_field"><h3>'.__('Contact Options').'</h3>';

    woocommerce_form_field_radio( 'newsletter_options', array(
    'type' => 'radio',
    'class' => array('newsletter_options form-row-wide'),
    'label' => __('We sometimes send out email newsletters on special offers and exciting new products from The Fold. Would you like to receive these emails? '),
    'placeholder' => __(''),
    'required' => false,
    'options' => array(

    'Yes' => 'Yes',
    'No' => 'No',

    )
    ), $checkout->get_value( 'newsletter_options' ));

    echo '</div>';

    }

    add_action('woocommerce_after_order_notes', 'mailinglist_options_field');

    function mailinglist_options_field( $checkout ) {

    echo '<div id="mailinglist_options_field"><p>'.__('').'</p>';

    woocommerce_form_field_radio( 'mailinglist_options', array(
    'type' => 'radio',
    'class' => array('mailinglist_options form-row-wide'),
    'label' => __('From time to time The Fold may make names and addresses from our mailing list available to carefully selected companies whose products may interest you. If you would prefer to have your name withheld please tick this box '),
    'placeholder' => __(''),
    'required' => false,
    'options' => array(

    'If you would prefer to have your name withheld please tick this box' => '',

    )
    ), $checkout->get_value( 'mailinglist_options' ));

    echo '</div>';

    }

    /**
    * 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['hear_about_us']) {
    // $woocommerce->add_error( __('Please tells us how you found our site') );
    }

    if (!$_POST['hear_about_us_other']) {
    // $woocommerce->add_error( __('Please tells us how you found our site') );
    }
    }

    add_action('woocommerce_checkout_process', 'my_newsletter_options_field_process');

    function my_newsletter_options_field_process() {
    global $woocommerce;

    // Check if set, if its not set add an error.
    if (!$_POST['newsletter_options']) {
    // $woocommerce->add_error( __('Please tells us how you found our site') );
    }
    }

    add_action('woocommerce_checkout_process', 'my_mailinglist_options_field_process');

    function my_mailinglist_options_field_process() {
    global $woocommerce;

    // Check if set, if its not set add an error.
    if (!$_POST['mailinglist_options']) {
    // $woocommerce->add_error( __('Please tells us how you found our site') );
    }
    }

    /**
    * Update the order meta with field value
    **/
    add_action('woocommerce_checkout_update_order_meta', 'hear_about_us_field_update_order_meta');

    function hear_about_us_field_update_order_meta( $order_id ) {
    if ($_POST['hear_about_us']) {
    update_post_meta( $order_id, 'hear_about_us', esc_attr($_POST['hear_about_us']) );
    }

    if ($_POST['hear_about_us_other']) {
    update_post_meta( $order_id, 'hear_about_us_other', esc_attr($_POST['hear_about_us_other']) );
    }
    }

    add_action('woocommerce_checkout_update_user_meta', 'my_custom_checkout_field_update_user_meta');

    function my_custom_checkout_field_update_user_meta( $user_id ) {
    if ($user_id && $_POST['hear_about_us']) update_user_meta( $user_id, 'hear_about_us', esc_attr($_POST['hear_about_us']) );
    if ($user_id && $_POST['hear_about_us_other']) update_user_meta( $user_id, 'hear_about_us_other', esc_attr($_POST['hear_about_us_other']) );
    }

    add_action('woocommerce_checkout_update_order_meta', 'newsletter_options_field_update_order_meta');

    function newsletter_options_field_update_order_meta( $order_id ) {
    if ($_POST['newsletter_options']) {
    update_post_meta( $order_id, 'newsletter_options', esc_attr($_POST['newsletter_options']) );
    }
    }
    add_action('woocommerce_checkout_update_user_meta', 'my_newsletter_options_field_update_user_meta');

    function my_newsletter_options_field_update_user_meta( $user_id ) {
    if ($user_id && $_POST['newsletter_options']) update_user_meta( $user_id, 'newsletter_options', esc_attr($_POST['newsletter_options']) );
    }

    add_action('woocommerce_checkout_update_order_meta', 'mailinglist_options_field_update_order_meta');

    function mailinglist_options_field_update_order_meta( $order_id ) {
    if ($_POST['mailinglist_options']) {
    update_post_meta( $order_id, 'mailinglist_options', esc_attr($_POST['mailinglist_options']) );
    }
    }
    add_action('woocommerce_checkout_update_user_meta', 'my_mailinglist_options_field_update_user_meta');

    function my_mailinglist_options_field_update_user_meta( $user_id ) {
    if ($user_id && $_POST['mailinglist_options']) update_user_meta( $user_id, 'mailinglist_options', esc_attr($_POST['mailinglist_options']) );
    }

    I just need the radio button choice “YES” to be preselected under Contact options on https://thefoldlondon.com/checkout/

    CONTACT OPTIONS

    We sometimes send out email newsletters on special offers and exciting new products from The Fold. Would you like to receive these emails?

    Yes >> this option should be preselected

    No

    and also how to change below this radio button to a text box.

    From time to time The Fold may make names and addresses from our mailing list available to carefully selected companies whose products may interest you. If you would prefer to have your name withheld please tick this box >> in here a tick box instead of a radio button would be ideal

    Really thanks for your help so far, hope this is not much to ask from you, looking forward to your suggestions!

    Best,

    Bill

    #88022

    1) Based on the docs: http://wcdocs.woothemes.com/snippets/tutorial-customising-checkout-fields-using-hooks-and-filters/ I’d say that it’s currently not possible to set a default value. You can try to set the placeholder value to ‘yes’ – maybe this creates the same effect like a default value but I’m not sure.

    2) You should be able to add your custom description text before the:

    echo '</div>';

    code line.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘small php edits on Abundance 1.4 WooCommerce 1.6.1’ is closed to new replies.