From 2d41e62773f8d65a369404d32fd548a5754cc31e Mon Sep 17 00:00:00 2001 From: Ian Weller Date: Tue, 9 Aug 2016 09:10:54 -0400 Subject: [PATCH] added woocommerce to theme --- functions.php | 114 ++++++++++++ woocommerce.php | 164 ++++++++++++++++++ woocommerce/archive-product.php | 107 ++++++++++++ woocommerce/content-product.php | 129 ++++++++++++++ woocommerce/content-product_cat.php | 82 +++++++++ woocommerce/content-single-product.php | 84 +++++++++ woocommerce/loop/price.php | 27 +++ woocommerce/single-product.php | 59 +++++++ .../single-product/add-to-cart/simple.php | 65 +++++++ .../single-product/add-to-cart/variable.php | 91 ++++++++++ .../variation-add-to-cart-button.php | 32 ++++ woocommerce/single-product/price.php | 33 ++++ 12 files changed, 987 insertions(+) create mode 100644 woocommerce.php create mode 100644 woocommerce/archive-product.php create mode 100644 woocommerce/content-product.php create mode 100644 woocommerce/content-product_cat.php create mode 100644 woocommerce/content-single-product.php create mode 100644 woocommerce/loop/price.php create mode 100644 woocommerce/single-product.php create mode 100644 woocommerce/single-product/add-to-cart/simple.php create mode 100644 woocommerce/single-product/add-to-cart/variable.php create mode 100644 woocommerce/single-product/add-to-cart/variation-add-to-cart-button.php create mode 100644 woocommerce/single-product/price.php diff --git a/functions.php b/functions.php index 6106c1e..7a5e16d 100644 --- a/functions.php +++ b/functions.php @@ -114,6 +114,120 @@ function glm_site_scripts() } +/* Woocommerce */ + +function get_product_category_by_id($cat_id) +{ +$category = get_term_by('id', $cat_id, 'product_cat', 'OBJECT'); +return $category; +} +add_filter( 'woocommerce_variation_option_name', 'display_price_in_variation_option_name' ); + +function display_price_in_variation_option_name( $term ) { + global $wpdb, $product; + + if ( empty( $term ) ) return $term; + if ( empty( $product->id ) ) return $term; + + $result = $wpdb->get_col( "SELECT slug FROM {$wpdb->prefix}terms WHERE name = '$term'" ); + + $term_slug = ( !empty( $result ) ) ? $result[0] : $term; + + $query = "SELECT postmeta.post_id AS product_id + FROM {$wpdb->prefix}postmeta AS postmeta + LEFT JOIN {$wpdb->prefix}posts AS products ON ( products.ID = postmeta.post_id ) + WHERE postmeta.meta_key LIKE 'attribute_%' + AND postmeta.meta_value = '$term_slug' + AND products.post_parent = $product->id"; + + $variation_id = $wpdb->get_col( $query ); + + $parent = wp_get_post_parent_id( $variation_id[0] ); + + if ( $parent > 0 ) { + $_product = new WC_Product_Variation( $variation_id[0] ); + return $term . ' (' . wp_kses( woocommerce_price( $_product->get_price() ), array() ) . ')'; + } + return $term; + +} +remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 ); +add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_single_add_to_cart', 10 ); +remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close', 10 ); +add_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_link_close', 30 ); + +remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_single_price', 40 ); +remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_single_price', 40 ); +add_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_single_price', 10 ); + +//addfilter('woocommercevariationpricehtml', 'myfunction', $product, 2); +// +//function myfunction($price, $product) { +// +//$price = getpostmeta( $product->variationid, 'regular_price'); +//// perform calculation on $price. +//return $price; +//} +//remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 ); +//add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 20 ); + +// Change number of thumbnails per row to 4 +add_filter ( 'woocommerce_product_thumbnails_columns', 'four_thumb_cols' ); + function four_thumb_cols() { + return 4; // .last class applied to every 4th thumbnail + } +// Change number or products per row to 3 +add_filter('loop_shop_columns', 'loop_columns',999); +function loop_columns() { + return 3; // 3 products per row +} +// Add WooCommerce excerpt to the item title on shop page +add_action('woocommerce_after_shop_loop_item_title','woocommerce_template_single_excerpt', 5); + +// Declare WooCommerce support +add_action( 'after_setup_theme', 'woocommerce_support' ); +function woocommerce_support() { + add_theme_support( 'woocommerce' ); +} +// WooCommerce number of products shown +add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 24;' ), 20 ); + +// Display Price For Variable Product With Same Variations Prices +add_filter('woocommerce_available_variation', function ($value, $object = null, $variation = null) { + if ($value['price_html'] == '') { + $value['price_html'] = '' . $variation->get_price_html() . ''; + } + return $value; +}, 10, 3); + +add_filter( 'woocommerce_product_tabs', 'woo_product_tab_edits' ); +function woo_product_tab_edits( $tabs ) { + // to always have the WooCommerce product inquiry tab display + $tabs['product_inquiry_tab'] = array( + 'title' => __( 'Product Inquiry', 'woocommerce' ), + 'priority' => 50, + 'callback' => 'woo_product_inquiry_content' + ); + // Rename Tab to Product Data + $tabs['additional_information']['title'] = __( 'More Info' ); // Rename the additional information tab + + return $tabs; +} + +function woo_product_inquiry_content() { + global $product; + echo do_shortcode('[gravityform id="2" title="true" description="true]'); +} +add_filter( 'gform_field_value_product_name', 'gform_add_product_name_field' ); +function gform_add_product_name_field( $value ) { + global $product; + return $product->get_title(); +} +add_filter( 'gform_field_value_product_sku', 'gform_add_product_sku_field' ); +function gform_add_product_sku_field( $value ) { + global $product; + return ( $sku = $product->get_sku() ) ? $sku : __( '(not set)', 'woocommerce' ); +} /* Header for posts*/ function glm_get_header() { diff --git a/woocommerce.php b/woocommerce.php new file mode 100644 index 0000000..aaf913f --- /dev/null +++ b/woocommerce.php @@ -0,0 +1,164 @@ + +
+ +
+
+
+ +
+ +
+ + + + + + + + + + + + +
+ +
+ + + + + +

+ + + + + + + + + + + + + + + + + + + + + + + + woocommerce_product_loop_start( false ), 'after' => woocommerce_product_loop_end( false ) ) ) ) : ?> + + + + + + +
+ +
+ '; + if(function_exists('pf_show_link')){echo pf_show_link();} + ?> + + + + + + + + + +
+ +
+
+
+ +
+ + \ No newline at end of file diff --git a/woocommerce/archive-product.php b/woocommerce/archive-product.php new file mode 100644 index 0000000..c4eb131 --- /dev/null +++ b/woocommerce/archive-product.php @@ -0,0 +1,107 @@ + + + + + + +

+ + + + + + + + + + + + + + + + + + + + + + + + woocommerce_product_loop_start( false ), 'after' => woocommerce_product_loop_end( false ) ) ) ) : ?> + + + + + + + + + + diff --git a/woocommerce/content-product.php b/woocommerce/content-product.php new file mode 100644 index 0000000..7c18d65 --- /dev/null +++ b/woocommerce/content-product.php @@ -0,0 +1,129 @@ +is_visible() ) { + return; +} + +// Increase loop count +$woocommerce_loop['loop']++; + +// Extra post classes +$classes = array(); +if ( 0 === ( $woocommerce_loop['loop'] - 1 ) % $woocommerce_loop['columns'] || 1 === $woocommerce_loop['columns'] ) { + $classes[] = 'first'; +} +if ( 0 === $woocommerce_loop['loop'] % $woocommerce_loop['columns'] ) { + $classes[] = 'last'; +} +?> + +
  • > +
    + +
    +
    + + + + +
    + More Info... + +
    +
    + +
    +
    + +
    +
    +
  • + +
  • > + + +
  • + + + + diff --git a/woocommerce/content-product_cat.php b/woocommerce/content-product_cat.php new file mode 100644 index 0000000..09595c9 --- /dev/null +++ b/woocommerce/content-product_cat.php @@ -0,0 +1,82 @@ +slug, $excludeCats ) ) { + return; +} + + +// Store loop count we're currently on +if ( empty( $woocommerce_loop['loop'] ) ) { + $woocommerce_loop['loop'] = 0; +} + +// Store column count for displaying the grid +if ( empty( $woocommerce_loop['columns'] ) ) { + $woocommerce_loop['columns'] = apply_filters( 'loop_shop_columns', 3 ); +} + +// Increase loop count +$woocommerce_loop['loop']++; +?> + + +count > 0 ) { ?> +
  • + + +
    + +
    +

    + name; + ?> +

    + + + + + +
  • + diff --git a/woocommerce/content-single-product.php b/woocommerce/content-single-product.php new file mode 100644 index 0000000..cf94b16 --- /dev/null +++ b/woocommerce/content-single-product.php @@ -0,0 +1,84 @@ + + + + +
    > + + + +
    + + + +
    + + + + + +
    + + diff --git a/woocommerce/loop/price.php b/woocommerce/loop/price.php new file mode 100644 index 0000000..dae22a4 --- /dev/null +++ b/woocommerce/loop/price.php @@ -0,0 +1,27 @@ + + +get_price_html() ) : ?> + + diff --git a/woocommerce/single-product.php b/woocommerce/single-product.php new file mode 100644 index 0000000..f0ad7ca --- /dev/null +++ b/woocommerce/single-product.php @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + diff --git a/woocommerce/single-product/add-to-cart/simple.php b/woocommerce/single-product/add-to-cart/simple.php new file mode 100644 index 0000000..d824598 --- /dev/null +++ b/woocommerce/single-product/add-to-cart/simple.php @@ -0,0 +1,65 @@ +is_purchasable() ) { + return; +} + +?> + +get_availability(); + $availability_html = empty( $availability['availability'] ) ? '' : '

    ' . esc_html( $availability['availability'] ) . '

    '; + + echo apply_filters( 'woocommerce_stock_html', $availability_html, $availability['availability'], $product ); +?> + +is_in_stock() ) : ?> + + + +
    + +
    + is_sold_individually() ) { + ?>Qty: apply_filters( 'woocommerce_quantity_input_min', 1, $product ), + 'max_value' => apply_filters( 'woocommerce_quantity_input_max', $product->backorders_allowed() ? '' : $product->get_stock_quantity(), $product ), + 'input_value' => ( 1 ) + ) ); + } + + ?> +
    + + + + +
    + + + + diff --git a/woocommerce/single-product/add-to-cart/variable.php b/woocommerce/single-product/add-to-cart/variable.php new file mode 100644 index 0000000..8d57d1b --- /dev/null +++ b/woocommerce/single-product/add-to-cart/variable.php @@ -0,0 +1,91 @@ + + +
    + + + +

    + + + has_child() ) { ?> + + + $options ) : ob_start(); ?> + + + + $ob) { +// $article = "a "; +// if (ctype_alpha($name) && preg_match('/^[aeiou]/i', $name)) { +// $article = "an "; +// } + echo str_ireplace('choose an option', 'Select '.$name, $ob ); + } ?> + + +
    + get_variation_default_attribute( $attribute_name ); + $selected = $product->get_variation_default_attribute( $attribute_name ); + wc_dropdown_variation_attribute_options( array( 'options' => $options, 'attribute' => $attribute_name, 'product' => $product, 'selected' => $selected ) ); + echo end( $attribute_keys ) === $attribute_name ? apply_filters( 'woocommerce_reset_variations_link', '' . __( 'Clear', 'woocommerce' ) . '' ) : ''; + ?> +
    + + + +
    + +
    + + + + + +
    + + diff --git a/woocommerce/single-product/add-to-cart/variation-add-to-cart-button.php b/woocommerce/single-product/add-to-cart/variation-add-to-cart-button.php new file mode 100644 index 0000000..5102718 --- /dev/null +++ b/woocommerce/single-product/add-to-cart/variation-add-to-cart-button.php @@ -0,0 +1,32 @@ + + +
    variations_button"> +
    + is_sold_individually() ) : ?> + Qty: + ( 1 ), + 'min_value' => apply_filters( 'woocommerce_quantity_input_min', 1, $product ), + 'max_value' => apply_filters( 'woocommerce_quantity_input_max', $product->backorders_allowed() ? '' : $product->get_stock_quantity(), $product ) + ) ); ?> + +
    + + + + +
    \ No newline at end of file diff --git a/woocommerce/single-product/price.php b/woocommerce/single-product/price.php new file mode 100644 index 0000000..c206593 --- /dev/null +++ b/woocommerce/single-product/price.php @@ -0,0 +1,33 @@ + +
    + + is_type( 'simple' ) ){ ?>

    get_price_html(); ?>

    + + + + + +
    \ No newline at end of file -- 2.17.1