ruạṛ
<?php function dc_enqueue_styles() { wp_enqueue_style( 'divi-parent', get_template_directory_uri() . '/style.css' ); wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array( 'divi-parent' ) ); } add_action( 'wp_enqueue_scripts', 'dc_enqueue_styles' ); add_action( 'wp_enqueue_scripts', 'my_enqueue_assets' ); function my_enqueue_assets() { wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' ); } /*Conditional re-order & rename of single product page tabs*/ add_filter( 'woocommerce_product_tabs', 'woo_reorder_tabs', 98 ); function woo_reorder_tabs( $tabs ) { global $post; $prod_terms = wp_get_post_terms( $post->ID, 'product_cat' ); foreach ( $prod_terms as $prod_term ) { // gets product cat id $product_cat_id = $prod_term->term_id; // gets an array of all parent category levels $product_parent_categories = get_ancestors( $product_cat_id, 'product_cat' ); if ( in_array( '108', $product_parent_categories ) ) { $tabs['additional_information']['priority'] = 5; // Additional information first $tabs['description']['priority'] = 10; // Description second $tabs['reviews']['priority'] = 15; // Reviews third } else { $tabs['description']['priority'] = 5; // Description first $tabs['additional_information']['priority'] = 10; // Additional information second $tabs['reviews']['priority'] = 15; // Reviews third } return $tabs; } } add_filter( 'woocommerce_product_tabs', 'woo_rename_tabs', 98 ); function woo_rename_tabs( $tabs ) { $tabs['additional_information']['title'] = __( 'Product Data' ); // Rename the additional information tab return $tabs; } add_filter( 'wc_product_enable_dimensions_display', '__return_false' ); /** * Load stylesheet */ function mmm_elegant_enqueue_css() { wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' ); } add_action( 'wp_enqueue_scripts', 'mmm_elegant_enqueue_css' ); /** * Fix “Full Width Menu” module * By default, when using the full width menu module in Divi, the Primary Menu will always be displayed * regardless of the menu selected in the module settings. To fix this add the following to the bottom * of your themes functions.php file: **/ function mmm_remove_theme_location($args) { if ( isset( $args['theme_location'] ) ) { unset( $args['theme_location'] ); } return $args; } add_filter('et_fullwidth_menu_args', 'mmm_remove_theme_location'); /** * Create a new "Divi" Mega Menu theme */ function load_divi_theme($themes) { $themes["divi"] = array( 'title' => 'Divi', 'container_background_from' => 'rgba(255, 255, 255, 0)', 'container_background_to' => 'rgba(255, 255, 255, 0)', 'arrow_up' => 'dash-f343', 'arrow_down' => 'dash-f347', 'arrow_left' => 'dash-f341', 'arrow_right' => 'dash-f345', 'menu_item_background_hover_from' => 'rgba(0, 0, 0, 0.03)', 'menu_item_background_hover_to' => 'rgba(0, 0, 0, 0.03)', 'menu_item_link_height' => '83px', 'menu_item_link_color' => 'rgb(51, 51, 51)', 'menu_item_link_color_hover' => 'rgb(34, 34, 34)', 'menu_item_highlight_current' => 'on', 'panel_background_from' => 'rgb(250, 250, 250)', 'panel_background_to' => 'rgb(250, 250, 250)', 'panel_width' => 'body', 'panel_inner_width' => '.container', 'panel_header_color' => 'rgb(51, 51, 51)', 'panel_header_font_weight' => 'normal', 'panel_header_padding_bottom' => '0px', 'panel_header_margin_bottom' => '10px', 'panel_header_border_color' => 'rgba(0, 0, 0, 0.2)', 'panel_header_border_bottom' => '1px', 'panel_font_size' => '14px', 'panel_font_color' => 'rgb(51, 51, 51)', 'panel_font_family' => 'inherit', 'panel_second_level_font_color' => 'rgb(51, 51, 51)', 'panel_second_level_font_color_hover' => 'rgb(51, 51, 51)', 'panel_second_level_text_transform' => 'uppercase', 'panel_second_level_font' => 'inherit', 'panel_second_level_font_size' => '16px', 'panel_second_level_font_weight' => 'normal', 'panel_second_level_font_weight_hover' => 'normal', 'panel_second_level_text_decoration' => 'none', 'panel_second_level_text_decoration_hover' => 'none', 'panel_second_level_margin_bottom' => '10px', 'panel_second_level_border_color' => 'rgb(221, 221, 221)', 'panel_second_level_border_bottom' => '1px', 'panel_third_level_font_color' => '#666', 'panel_third_level_font_color_hover' => '#666', 'panel_third_level_font' => 'inherit', 'panel_third_level_font_size' => '14px', 'flyout_menu_background_from' => 'rgb(250, 250, 250)', 'flyout_menu_background_to' => 'rgb(250, 250, 250)', 'flyout_menu_item_divider_color' => 'rgba(0, 0, 0, 0.1)', 'flyout_background_from' => 'rgba(255, 255, 255, 0)', 'flyout_background_to' => 'rgba(255, 255, 255, 0)', 'flyout_background_hover_from' => 'rgba(0, 0, 0, 0.03)', 'flyout_background_hover_to' => 'rgba(0, 0, 0, 0.03)', 'flyout_link_size' => '14px', 'flyout_link_color' => '#666', 'flyout_link_color_hover' => '#666', 'flyout_link_family' => 'inherit', 'responsive_breakpoint' => '980px', 'shadow_vertical' => '2px', 'transitions' => 'on', 'mobile_columns' => '1', 'toggle_background_from' => 'rgb(225, 225, 225)', 'toggle_background_to' => 'rgb(225, 225, 225)', 'toggle_font_color' => 'rgb(51, 51, 51)', 'mobile_background_from' => 'rgb(225, 225, 225)', 'mobile_background_to' => 'rgb(225, 225, 225)', 'custom_css' => '', ); return $themes; } add_filter('megamenu_themes', 'load_divi_theme'); add_filter( 'woocommerce_currencies', 'add_my_currency' ); function add_my_currency( $currencies ) { $currencies['NZD'] = __( 'Currency name', 'woocommerce' ); return $currencies; } add_filter('woocommerce_currency_symbol', 'add_my_currency_symbol', 10, 2); function add_my_currency_symbol( $currency_symbol, $currency ) { switch( $currency ) { case 'NZD': $currency_symbol = 'NZ$'; break; } return $currency_symbol; } function mmm_restrict_search_to_products($html) { return $html . "<input type='hidden' name='post_type' value='product' />"; } add_filter('megamenu_search_inputs', 'mmm_restrict_search_to_products'); /** * @snippet WooCommerce Disable Payment Gateway for a Specific Country * @how-to Watch tutorial @ https://businessbloomer.com/?p=19055 * @sourcecode https://businessbloomer.com/?p=164 * @author Rodolfo Melogli * @compatible WooCommerce 2.4.7 */ function payment_gateway_disable_country( $available_gateways ) { global $woocommerce; if ( isset( $available_gateways['bacs'] ) && $woocommerce->customer->get_country() == 'AU' ) { unset( $available_gateways['bacs'] ); } return $available_gateways; } add_filter( 'woocommerce_available_payment_gateways', 'payment_gateway_disable_country' ); /* Code to modify the back order text on the single product & cart pages */ function backorder_text($availability) { foreach($availability as $i) { $availability = str_replace('Available on back-order', 'Available on back order. 5-10 working days for delivery', $availability); } return $availability; } add_filter('woocommerce_get_availability', 'backorder_text'); function woocommerce_custom_cart_item_name( $_product_title, $cart_item, $cart_item_key ){ if ( $cart_item['data']->backorders_require_notification() && $cart_item['data']->is_on_backorder( $cart_item['quantity'] ) ) { $_product_title .= __( ' - 5-10 working day delivery', 'woocommerce' ); } return $_product_title; } add_filter( 'woocommerce_cart_item_name', 'woocommerce_custom_cart_item_name', 10, 3); /** * Change min password strength. * @param int $strength * @return int */ add_filter( 'woocommerce_min_password_strength', 'wc_min_password_strength', 10, 1 ); function wc_min_password_strength( $strength ) { return 2; } add_action( 'wp_enqueue_scripts', 'my_strength_meter_localize_script' ); function my_strength_meter_localize_script() { wp_localize_script( 'password-strength-meter', 'pwsL10n', array( 'empty' => __( 'But... it\'s empty!', 'theme-domain' ), 'short' => __( 'Too short!', 'theme-domain' ), 'bad' => __( 'Try to add a symbol & a number or 2', 'theme-domain' ), 'good' => __( 'That will do, but more is always welcome.', 'theme-domain' ), 'strong' => __( 'Now, that\'s a password!', 'theme-domain' ), 'mismatch' => __( 'They are completely different, come on!', 'theme-domain' ) ) ); } /*change password strength hint text*/ add_filter( 'woocommerce_get_script_data', 'my_strength_meter_custom_strings', 10, 2 ); function my_strength_meter_custom_strings( $data, $handle ) { if ( 'wc-password-strength-meter' === $handle ) { $data_new = array( 'i18n_password_error' => esc_attr__( 'Keep going! We\'re just making sure your account is safe.'), 'i18n_password_hint' => esc_attr__( 'HINT: The password should be at least six characters long, contain upper case and lower case characters and numbers. If you can chuck in some symbols as well that would be epic!') ); return array_merge( $data, $data_new ); } return $data; } /*Add Custom Metabox to Woocommerce Products*/ ## ---- 1. Backend ---- ## // Adding a custom Meta container to admin products pages add_action( 'add_meta_boxes', 'create_custom_meta_box' ); if ( ! function_exists( 'create_custom_meta_box' ) ) { function create_custom_meta_box() { add_meta_box( 'custom_product_meta_box', // id __( 'Cutting Data <em>(optional)</em>', 'cmb' ), // title 'add_custom_content_meta_box', // callback 'product', // custom post type name 'normal', // context 'default' // priority ); } } // Custom metabox content in admin product pages if ( ! function_exists( 'add_custom_content_meta_box' ) ){ function add_custom_content_meta_box( $post ){ $prefix = 'cpx_'; // global $prefix; $cuttingdata = get_post_meta($post->ID, $prefix.'cuttingdata_wysiwyg', true) ? get_post_meta($post->ID, $prefix.'cuttingdata_wysiwyg', true) : ''; $args['textarea_rows'] = 6; echo '<p>'.__( 'Cutting Data', 'cmb' ).'</p>'; wp_editor( $cuttingdata, 'cuttingdata_wysiwyg', $args ); echo '<input type="hidden" name="custom_product_field_nonce" value="' . wp_create_nonce() . '">'; } } //Save the data of the Meta field add_action( 'save_post', 'save_custom_content_meta_box', 10, 1 ); if ( ! function_exists( 'save_custom_content_meta_box' ) ){ function save_custom_content_meta_box( $post_id ) { $prefix = 'cpx_'; // global $prefix; // We need to verify this with the proper authorization (security stuff). // Check if our nonce is set. if ( ! isset( $_POST[ 'custom_product_field_nonce' ] ) ) { return $post_id; } $nonce = $_REQUEST[ 'custom_product_field_nonce' ]; //Verify that the nonce is valid. if ( ! wp_verify_nonce( $nonce ) ) { return $post_id; } // If this is an autosave, our form has not been submitted, so we don't want to do anything. if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { return $post_id; } // Check the user's permissions. if ( 'product' == $_POST[ 'post_type' ] ){ if ( ! current_user_can( 'edit_product', $post_id ) ) return $post_id; } else { if ( ! current_user_can( 'edit_post', $post_id ) ) return $post_id; } // Sanitize user input and update the meta field in the database. update_post_meta( $post_id, $prefix.'cuttingdata_wysiwyg', wp_kses_post($_POST[ 'cuttingdata_wysiwyg' ]) ); } } ## ---- 2. Front-end ---- ## // Create custom tabs in product single pages add_filter( 'woocommerce_product_tabs', 'custom_product_tabs' ); function custom_product_tabs( $tabs ) { global $post; $product_cuttingdata = get_post_meta( $post->ID, 'cpx_cuttingdata_wysiwyg', true ); if ( ! empty( $product_cuttingdata ) ) $tabs['cuttingdata_tab'] = array( 'title' => __( 'Cutting Data', 'woocommerce' ), 'priority' => 45, 'callback' => 'cuttingdata_product_tab_content' ); return $tabs; } // Add content to custom tab in product single pages (1) function cuttingdata_product_tab_content() { global $post; $product_cuttingdata = get_post_meta( $post->ID, 'cpx_cuttingdata_wysiwyg', true ); if ( ! empty( $product_cuttingdata ) ) { echo '<h2>' . __( 'Product Cutting Data', 'woocommerce' ) . '</h2>'; // Updated to apply the_content filter to WYSIWYG content echo apply_filters( 'the_content', $product_cuttingdata ); } } //Allowing step file upload to media library function my_myme_types($mime_types){ $mime_types['step'] = 'application/step'; //Adding step extension return $mime_types; } add_filter('upload_mimes', 'my_myme_types', 1, 1);
cải xoăn