| 1 | <?php |
|---|
| 2 | /** |
|---|
| 3 | * Woocommerce wrappers |
|---|
| 4 | * |
|---|
| 5 | * @package Sydney |
|---|
| 6 | */ |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | if ( !class_exists('WooCommerce') ) |
|---|
| 10 | return; |
|---|
| 11 | |
|---|
| 12 | /** |
|---|
| 13 | * Declare support |
|---|
| 14 | */ |
|---|
| 15 | function sydney_wc_support() { |
|---|
| 16 | add_theme_support( 'woocommerce' ); |
|---|
| 17 | add_theme_support( 'wc-product-gallery-lightbox' ); |
|---|
| 18 | add_theme_support( 'wc-product-gallery-slider' ); |
|---|
| 19 | } |
|---|
| 20 | add_action( 'after_setup_theme', 'sydney_wc_support' ); |
|---|
| 21 | |
|---|
| 22 | /** |
|---|
| 23 | * Add and remove actions |
|---|
| 24 | */ |
|---|
| 25 | function sydney_woo_actions() { |
|---|
| 26 | remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10); |
|---|
| 27 | remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10); |
|---|
| 28 | remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation_add_to_cart_button', 20 ); |
|---|
| 29 | add_action('woocommerce_before_main_content', 'sydney_wc_wrapper_start', 10); |
|---|
| 30 | add_action('woocommerce_after_main_content', 'sydney_wc_wrapper_end', 10); |
|---|
| 31 | } |
|---|
| 32 | add_action('wp','sydney_woo_actions'); |
|---|
| 33 | |
|---|
| 34 | /** |
|---|
| 35 | * Theme wrappers |
|---|
| 36 | */ |
|---|
| 37 | function sydney_wc_wrapper_start() { |
|---|
| 38 | echo '<div id="primary" class="content-area col-md-9">'; |
|---|
| 39 | echo '<main id="main" class="site-main" role="main">'; |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | function sydney_wc_wrapper_end() { |
|---|
| 43 | echo '</main>'; |
|---|
| 44 | echo '</div>'; |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | /** |
|---|
| 48 | * Archive titles |
|---|
| 49 | */ |
|---|
| 50 | function sydney_woo_archive_title() { |
|---|
| 51 | echo '<h3 class="archive-title">'; |
|---|
| 52 | echo woocommerce_page_title(); |
|---|
| 53 | echo '</h3>'; |
|---|
| 54 | } |
|---|
| 55 | add_filter( 'woocommerce_show_page_title', 'sydney_woo_archive_title' ); |
|---|
| 56 | |
|---|
| 57 | /** |
|---|
| 58 | * Remove default WooCommerce CSS |
|---|
| 59 | */ |
|---|
| 60 | function sydney_dequeue_styles( $enqueue_styles ) { |
|---|
| 61 | unset( $enqueue_styles['woocommerce-general'] ); |
|---|
| 62 | return $enqueue_styles; |
|---|
| 63 | } |
|---|
| 64 | add_filter( 'woocommerce_enqueue_styles', 'sydney_dequeue_styles' ); |
|---|
| 65 | |
|---|
| 66 | /** |
|---|
| 67 | * Enqueue custom CSS for Woocommerce |
|---|
| 68 | */ |
|---|
| 69 | function sydney_woocommerce_css() { |
|---|
| 70 | wp_enqueue_style( 'sydney-wc-css', get_template_directory_uri() . '/woocommerce/css/wc.css' ); |
|---|
| 71 | } |
|---|
| 72 | add_action( 'wp_enqueue_scripts', 'sydney_woocommerce_css', 1 ); |
|---|
| 73 | |
|---|
| 74 | /** |
|---|
| 75 | * Number of related products |
|---|
| 76 | */ |
|---|
| 77 | function sydney_related_products_args( $args ) { |
|---|
| 78 | $args['posts_per_page'] = 3; |
|---|
| 79 | $args['columns'] = 3; |
|---|
| 80 | return $args; |
|---|
| 81 | } |
|---|
| 82 | add_filter( 'woocommerce_output_related_products_args', 'sydney_related_products_args' ); |
|---|
| 83 | |
|---|
| 84 | /** |
|---|
| 85 | * Variable products button |
|---|
| 86 | */ |
|---|
| 87 | function sydney_single_variation_add_to_cart_button() { |
|---|
| 88 | global $product; |
|---|
| 89 | ?> |
|---|
| 90 | <div class="woocommerce-variation-add-to-cart variations_button"> |
|---|
| 91 | <?php do_action( 'woocommerce_before_add_to_cart_button' ); ?> |
|---|
| 92 | |
|---|
| 93 | <?php |
|---|
| 94 | do_action( 'woocommerce_before_add_to_cart_quantity' ); |
|---|
| 95 | |
|---|
| 96 | woocommerce_quantity_input( array( |
|---|
| 97 | 'input_value' => isset( $_POST['quantity'] ) ? wc_stock_amount( $_POST['quantity'] ) : 1, |
|---|
| 98 | ) ); |
|---|
| 99 | |
|---|
| 100 | do_action( 'woocommerce_after_add_to_cart_quantity' ); |
|---|
| 101 | ?> |
|---|
| 102 | <button type="submit" class="roll-button cart-button"><?php echo esc_html( $product->single_add_to_cart_text() ); ?></button> |
|---|
| 103 | <input type="hidden" name="add-to-cart" value="<?php echo absint( $product->get_id() ); ?>" /> |
|---|
| 104 | <input type="hidden" name="product_id" value="<?php echo absint( $product->get_id() ); ?>" /> |
|---|
| 105 | <input type="hidden" name="variation_id" class="variation_id" value="0" /> |
|---|
| 106 | </div> |
|---|
| 107 | <?php |
|---|
| 108 | } |
|---|
| 109 | add_action( 'woocommerce_single_variation', 'sydney_single_variation_add_to_cart_button', 21 ); |
|---|