WC_Full_Page_Add_To_Cart

Plugin Name: WooCommerce Stacked Product Layout Description: A handy plugin for stacking the add-to-cart section of complex WooCommerce product types below the main product image and summary.

Defined (1)

The class is defined in the following location(s).

/woocommerce-full-width-add-to-cart.php  
  1. class WC_Full_Page_Add_To_Cart { 
  2.  
  3. public static function init() { 
  4.  
  5. add_action( 'init', __CLASS__ . '::wc_fw_single_add_to_cart' ); 
  6.  
  7. // Add "Add-to-Cart Layout" section under "Products" 
  8. add_filter( 'woocommerce_get_sections_products', __CLASS__ . '::wc_fw_add_section' ); 
  9.  
  10. // Add settings in the new section 
  11. add_filter( 'woocommerce_get_settings_products', __CLASS__ . '::wc_fw_all_settings', 10, 2 ); 
  12.  
  13. public static function wc_fw_single_add_to_cart() { 
  14.  
  15. // Unhook 'woocommerce_template_single_add_to_cart' from 'woocommerce_single_product_summary' 30 
  16. remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 ); 
  17.  
  18. // Hook wc_fw_template_single_add_to_cart into 'woocommerce_template_single_add_to_cart' 30 and run 'woocommerce_single_product_summary' through it only if the product type doesn't need to be moved. 
  19. add_action( 'woocommerce_single_product_summary', __CLASS__ . '::wc_fw_template_single_add_to_cart', 30 ); 
  20.  
  21. // Hook wc_fw_single_add_to_cart_after_summary into 'woocommerce_after_single_product_summary' 30 and run 'woocommerce_single_product_summary' through it if the product type needs to be moved. 
  22. add_action( 'woocommerce_after_single_product_summary', __CLASS__ . '::wc_fw_single_add_to_cart_after_summary', 5 ); 
  23.  
  24. public static function wc_fw_get_types_to_move() { 
  25.  
  26. $moved_types = get_option( 'wc_fw_add_to_cart_layout_types', array() ); 
  27.  
  28. return apply_filters( 'woocommerce_full_width_add_to_cart_types', $moved_types ); 
  29.  
  30. public static function wc_fw_single_add_to_cart_after_summary() { 
  31.  
  32. global $product; 
  33.  
  34. // Get types to move 
  35. $moved_types = self::wc_fw_get_types_to_move(); 
  36.  
  37. if ( ! empty( $moved_types ) && is_array( $moved_types ) && in_array( $product->product_type, $moved_types ) ) { 
  38. echo '<div class="add-to-cart-summary" style="clear:both;">'; 
  39. woocommerce_template_single_add_to_cart(); 
  40. echo '</div>'; 
  41.  
  42. public static function wc_fw_template_single_add_to_cart() { 
  43.  
  44. global $product; 
  45.  
  46. // Get types to move 
  47. $moved_types = self::wc_fw_get_types_to_move(); 
  48.  
  49. if ( empty( $moved_types ) || ( ! is_array( $moved_types ) ) ) 
  50. woocommerce_template_single_add_to_cart(); 
  51. elseif ( ! in_array( $product->product_type, $moved_types ) ) 
  52. woocommerce_template_single_add_to_cart(); 
  53.  
  54.  
  55. public static function wc_fw_add_section( $sections ) { 
  56.  
  57. $sections[ 'wc_fw_add_to_cart' ] = __( 'Add-to-Cart Form Layout', 'woocommerce-full-width-add-to-cart' ); 
  58.  
  59. return $sections; 
  60.  
  61. public static function wc_fw_all_settings( $settings, $current_section ) { 
  62.  
  63. if ( $current_section == 'wc_fw_add_to_cart' ) { 
  64.  
  65. $settings = array(); 
  66.  
  67. // Add Title to the Settings 
  68. $settings[] = array( 'name' => __( 'Add-to-Cart Form Layout Settings', 'woocommerce-full-width-add-to-cart' ), 'type' => 'title', 'desc' => __( 'If the add-to-cart form of your products appears very narrow or squeezed, you can move the add-to-cart section under the product image and summary.', 'woocommerce-full-width-add-to-cart' ), 'id' => 'wc_fw_add_to_cart' ); 
  69.  
  70. // Add product type multi-select 
  71. $settings[] = array( 
  72. 'id' => 'wc_fw_add_to_cart_layout_types',  
  73. 'title' => __( 'Product Types', 'woocommerce-full-width-add-to-cart' ),  
  74. 'type' => 'multiselect',  
  75. 'class' => 'chosen_select',  
  76. 'css' => 'width: 450px;',  
  77. 'desc' => '<div>' . __( 'The product types selected here will use the modified, full-width layout.', 'woocommerce-full-width-add-to-cart' ) . '</div>',  
  78. 'default' => '',  
  79. 'options' => self::get_product_types(),  
  80. 'custom_attributes' => array( 
  81. 'data-placeholder' => __( 'Select some product types…', 'woocommerce-full-width-add-to-cart' ) 
  82. ); 
  83.  
  84. $settings[] = array( 'type' => 'sectionend', 'id' => 'wc_fw_add_to_cart' ); 
  85.  
  86. return $settings; 
  87.  
  88. } else { 
  89.  
  90. return $settings; 
  91.  
  92.  
  93.  
  94. public static function get_product_types() { 
  95.  
  96. $types = array(); 
  97.  
  98. $terms = get_terms( 'product_type', array( 'hide_empty' => 0 ) ); 
  99.  
  100. foreach ( $terms as $term ) 
  101. $types[ $term->slug ] = ucfirst( $term->name ) . ' (' . $term->slug . ')'; 
  102.  
  103. return $types;