MrVirabyan

fucnction

Apr 28th, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.53 KB | None | 0 0
  1. <?php
  2. if ( ! defined( 'ABSPATH' ) ) {
  3. exit; // Exit if accessed directly
  4. }
  5. add_action( 'wp_enqueue_scripts', 'awooc_enqueue_script_style', 100 );
  6. function awooc_enqueue_script_style() {
  7. wp_enqueue_script( 'awooc-scripts', AWOOC_PLUGIN_URI .
  8. 'assets/js/awooc-scripts.js', array( 'jquery' ), AWOOC_PLUGIN_VER, true );
  9. wp_enqueue_style( 'awooc-styles', AWOOC_PLUGIN_URI . 'assets/css/awooc-styles.css', array(), AWOOC_PLUGIN_VER );
  10. wp_localize_script( 'awooc-scripts', 'awooc_scrpts', array(
  11. 'url' => admin_url( 'admin-ajax.php' ),
  12. 'nonce' => wp_create_nonce( 'awooc-nonce' ),
  13. ) );
  14. }
  15.  
  16. add_action( 'wp_ajax_awooc_ajax_variant_order', 'awooc_ajax_scripts_callback' );
  17. add_action( 'wp_ajax_nopriv_awooc_ajax_variant_order', 'awooc_ajax_scrpts_callback' );
  18. function awooc_ajax_scripts_callback() {
  19.  
  20. if ( ! wp_verify_nonce( $_POST['nonce'], 'awooc-nonce' ) ) {
  21. wp_die( 'Данные отправлены с левого адреса' );
  22. }
  23. $product_var_id = $_POST['id'] ? esc_attr( $_POST['id'] ) : 0;
  24. if ( 0 == $product_var_id ) {
  25. wp_die();
  26. }
  27. $product = wc_get_product( $product_var_id );
  28. $attributes = $product->get_attributes();
  29. $product_variable = new WC_Product_Variable( $product->get_parent_id() );
  30. $variations = $product_variable->get_variation_attributes();
  31. $attr_name = array();
  32. foreach ( $attributes as $attr => $value ) {
  33. $attr_label = wc_attribute_label( $attr );
  34. $meta = get_post_meta( $product_var_id, wc_variation_attribute_name( $attr ), true );
  35. $term = get_term_by( 'slug', $meta, $attr );
  36. if ( false != $term ) {
  37. $attr_name[] = $attr_label . ': ' . $term->name;
  38. }
  39. }
  40. if ( empty( $attr_name ) ) {
  41. foreach ( $variations as $key => $item ) {
  42. $attr_name[] = $key . ': ' . implode( array_intersect( $item, $attributes ) );
  43. }
  44. }
  45. $product_var_attr = esc_html( implode( '; ', $attr_name ) );
  46. wp_send_json( $product_var_attr );
  47. wp_die();
  48. }
  49.  
  50. add_filter( 'woocommerce_is_purchasable', 'awooc_disable_add_to_cart' );
  51. function awooc_disable_add_to_cart() {
  52. if ( is_product() ) {
  53. return true;
  54. } elseif ( 'no' == get_option( 'woocommerce_awooc_mode_catalog' ) ) {
  55. return true;
  56. }
  57.  
  58. return false;
  59. }
  60.  
  61. function awooc_enable_add_to_card() {
  62. ?>
  63. <style>
  64. .single_add_to_cart_button,
  65. input.qty {
  66. display: inline-block !important;
  67. }
  68. </style>
  69. <?php
  70. }
  71.  
  72. add_action( 'woocommerce_after_add_to_cart_button', 'awooc_add_custom_button' );
  73. function awooc_add_custom_button() {
  74. global $product;
  75. if ( 'no' == get_option( 'woocommerce_awooc_mode_catalog' ) ) {
  76. awooc_enable_add_to_card();
  77. }
  78. ?>
  79. <a href="#awooc-form-custom-order" data-value-product-id="<?php echo esc_attr( $product->get_id() ); ?>"
  80. class="awooc-custom-order button alt"><?php echo esc_html( get_option( 'woocommerce_awooc_title_button' ) ); ?></a>
  81. <?php
  82. }
  83.  
  84. add_action( 'wp_footer', 'awooc_form_custom_order' );
  85. function awooc_form_custom_order() {
  86. global $product;
  87. if ( ! is_product() ) {
  88. return;
  89. }
  90. $elements = get_option( 'woocommerce_awooc_select_item' );
  91. if (!is_array($elements)){
  92. return;
  93. }
  94. ?>
  95. <div id="awooc-form-custom-order" class="awooc-form-custom-order awooc-hide">
  96. <div class="awooc-custom-order-wrap">
  97. <div class="awooc-col">
  98. <?php
  99. if ( ! in_array( 'image', $elements ) ):
  100. $post_thumbnail_id = get_post_thumbnail_id( $product->get_id() );
  101. $full_size_image = wp_get_attachment_image_src( $post_thumbnail_id, 'shop_single' );
  102. ?>
  103. <div class="awooc-form-custom-order-img">
  104. <img src="<?php echo esc_url( $full_size_image[0] ) ?>" alt="">
  105. </div>
  106. <?php endif;
  107. if ( ! in_array( 'price', $elements ) ):?>
  108. <div class="awooc-form-custom-order-price"></div>
  109. <?php endif;
  110. if ( ! in_array( 'sku', $elements ) ):?>
  111. <div class="awooc-form-custom-order-sku"></div>
  112. <?php endif; ?>
  113. </div>
  114. <div class="awooc-col">
  115. <?php if ( ! in_array( 'title', $elements ) ): ?>
  116. <h2 class="awooc-form-custom-order-title"><?php echo esc_html( $product->get_title() ); ?></h2>
  117. <?php endif;
  118. if ( ! in_array( 'attr', $elements ) ):?>
  119. <div class="awooc-form-custom-order-attr"></div>
  120. <?php endif;
  121. if ( ! empty( get_option( 'woocommerce_awooc_select_form' ) ) ) {
  122. echo do_shortcode( '[contact-form-7 id="' .
  123. esc_html( get_option( 'woocommerce_awooc_select_form' ) ) . '"]' );
  124. }
  125. ?>
  126. <iframe src="https://zavlinel.ru/registration/kontakt.php" style="border:none;hight:300px"></iframe>
  127. </div>
  128. </div>
  129. </div>
  130. <?php
  131. }
Add Comment
Please, Sign In to add comment