Untitled
unknown
plain_text
a month ago
8.1 kB
4
Indexable
Never
<?php // Exit if accessed directly if ( !defined( 'ABSPATH' ) ) exit; // BEGIN ENQUEUE PARENT ACTION // AUTO GENERATED - Do not modify or remove comment markers above or below: if ( !function_exists( 'chld_thm_cfg_locale_css' ) ): function chld_thm_cfg_locale_css( $uri ){ if ( empty( $uri ) && is_rtl() && file_exists( get_template_directory() . '/rtl.css' ) ) $uri = get_template_directory_uri() . '/rtl.css'; return $uri; } endif; add_filter( 'locale_stylesheet_uri', 'chld_thm_cfg_locale_css' ); if ( !function_exists( 'child_theme_configurator_css' ) ): function child_theme_configurator_css() { wp_enqueue_style( 'chld_thm_cfg_child', trailingslashit( get_stylesheet_directory_uri() ) . 'style.css', array( 'astra-theme-css','woocommerce-layout','woocommerce-smallscreen','woocommerce-general' ) ); } endif; add_action( 'wp_enqueue_scripts', 'child_theme_configurator_css', 10 ); // END ENQUEUE PARENT ACTION add_filter( 'wc_product_sku_enabled', '__return_false' ); add_action('woocommerce_product_options_general_product_data', 'woocommerce_product_custom_fields_child'); // Save Fields add_action('woocommerce_process_product_meta', 'woocommerce_product_custom_fields_save_child'); function woocommerce_product_custom_fields_child() { global $woocommerce, $post; echo '<div class="product_custom_field">'; // Custom Product Text Field woocommerce_wp_text_input( array( 'id' => '_zoom_link', 'placeholder' => 'Zoom Link', 'label' => __('Zoom Link', 'woocommerce'), 'desc_tip' => 'true' ) ); echo '</div>'; echo '<div class="product_custom_field">'; // Custom Product Text Field woocommerce_wp_text_input( array( 'id' => '_zoom_link_passcode', 'placeholder' => 'Zoom Link Passcode', 'label' => __('Zoom Link Passcode', 'woocommerce'), 'desc_tip' => 'true' ) ); echo '</div>'; } function woocommerce_product_custom_fields_save_child($post_id) { // Custom Product Text Field $woocommerce_custom_product_text_field = $_POST['_zoom_link']; if (!empty($woocommerce_custom_product_text_field)) update_post_meta($post_id, '_zoom_link', esc_attr($woocommerce_custom_product_text_field)); $zoom_link_passcode = $_POST['_zoom_link_passcode']; if (!empty($zoom_link_passcode)) update_post_meta($post_id, '_zoom_link_passcode', esc_attr($zoom_link_passcode)); } add_action( 'woocommerce_variation_options_pricing', 'bbloomer_add_custom_field_to_variations_child', 10, 3 ); function bbloomer_add_custom_field_to_variations_child( $loop, $variation_data, $variation ) { woocommerce_wp_text_input( array( 'id' => '_zoom_link_var[' . $loop . ']', 'class' => 'short', 'label' => __( 'Zoom Link', 'woocommerce' ), 'value' => get_post_meta( $variation->ID, '_zoom_link_var', true ) ) ); woocommerce_wp_text_input( array( 'id' => '_zoom_link_var_passcode[' . $loop . ']', 'class' => 'short', 'label' => __( 'Zoom Link Passcode', 'woocommerce' ), 'value' => get_post_meta( $variation->ID, '_zoom_link_var_passcode', true ) ) ); } // ----------------------------------------- // 2. Save custom field on product variation save add_action( 'woocommerce_save_product_variation', 'bbloomer_save_custom_field_variations_child', 10, 2 ); function bbloomer_save_custom_field_variations_child( $variation_id, $i ) { $_zoom_link_var = $_POST['_zoom_link_var'][$i]; if ( isset( $_zoom_link_var ) ) update_post_meta( $variation_id, '_zoom_link_var', esc_attr( $_zoom_link_var ) ); $_zoom_link_var_passcode = $_POST['_zoom_link_var_passcode'][$i]; if ( isset( $_zoom_link_var_passcode ) ) update_post_meta( $variation_id, '_zoom_link_var_passcode', esc_attr( $_zoom_link_var_passcode ) ); } // ----------------------------------------- // 3. Store custom field value into variation data add_filter( 'woocommerce_available_variation', 'bbloomer_add_custom_field_variation_data_child' ); function bbloomer_add_custom_field_variation_data_child( $variations ) { $variations['_zoom_link_var'] = '<div class="woocommerce_custom_field">Zoom Link: <span>' . get_post_meta( $variations[ 'variation_id' ], '_zoom_link_var', true ) . '</span></div>'; return $variations; $variations['$_zoom_link_var_passcode'] = '<div class="woocommerce_custom_field">Zoom Link Passcode: <span>' . get_post_meta( $variations[ 'variation_id' ], '$_zoom_link_var_passcode', true ) . '</span></div>'; return $variations; } /** * Remove "Description" Heading Title @ WooCommerce Single Product Tabs */ add_filter( 'woocommerce_product_description_heading', '__return_null' ); add_action( 'woocommerce_review_order_before_submit', 'bt_add_checkout_checkbox', 10 ); /** * Add WooCommerce Checkbox checkout */ function bt_add_checkout_checkbox() { woocommerce_form_field( 'dataskyddsforordningen', array( // CSS ID 'type' => 'checkbox', 'class' => array('form-row mycheckbox'), // CSS Class 'label_class' => array('woocommerce-form__label woocommerce-form__label-for-checkbox checkbox'), 'input_class' => array('woocommerce-form__input woocommerce-form__input-checkbox input-checkbox'), 'required' => true, // Mandatory or Optional 'label' => 'Jag har läst och godkänner info om <a href="/dataskyddsforordningen" target="_blank" rel="noopener">dataskyddsforordningen</a>', // Label and Link )); } add_action( 'woocommerce_checkout_process', 'bt_add_checkout_checkbox_warning' ); /** * Alert if checkbox not checked */ function bt_add_checkout_checkbox_warning() { if ( ! (int) isset( $_POST['dataskyddsforordningen'] ) ) { wc_add_notice( __( 'Please acknowledge the Checkbox' ), 'error' ); } } function remove_image_zoom_support() { remove_theme_support( 'wc-product-gallery-zoom' ); } add_action( 'wp', 'remove_image_zoom_support', 100 ); add_filter( 'tec_views_v2_use_subscribe_links', '__return_false' ); function custom_url_redirect() { if (preg_match('/^\/event\/(.*)$/', $_SERVER['REQUEST_URI'], $matches)) { wp_redirect(home_url() . '/' . $matches[1], 301); exit(); } } add_action('template_redirect', 'custom_url_redirect'); function replace_header_icon_based_on_cart_with_jquery() { // Check if WooCommerce is active if ( class_exists( 'WooCommerce' ) ) { // Get the cart total $cart_total = WC()->cart->get_cart_contents_count(); $custom_page_url = is_user_logged_in() ? site_url('/medlemssidan') : site_url('/login'); // Remove currency symbols and commas ?> <script type="text/javascript"> jQuery(document).ready(function($) { // Get the cart total from PHP var cartTotal = <?php echo $cart_total; ?>; // Check if the cart total is 0 or empty if (cartTotal === 0 ) { // Cart is empty or total is not a number, replace HTML with user icon $('.elementor-icon-wrapper:first').html('<a class="elementor-icon" href="<?php echo esc_url( $custom_page_url );?>"><i class="fas fa-user-lock" aria-hidden="true"></i></a>'); } }); </script> <?php } } add_action('wp_footer', 'replace_header_icon_based_on_cart_with_jquery'); function modify_login_link() { if (is_user_logged_in()) { ?> <script type="text/javascript"> document.addEventListener("DOMContentLoaded", function() { var loginLinks = document.querySelectorAll('.elementor-button'); loginLinks.forEach(function(link) { if (link.textContent.trim() === 'mina sidor') { var baseUrl = "<?php echo esc_url( home_url( '/' ) ); ?>"; var newHref = baseUrl + 'medlemssidan/'; link.setAttribute('href', newHref); } }); }); </script> <?php } } add_action('wp_footer', 'modify_login_link');
Leave a Comment