add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 250, 250 );
function true_remove_default_sizes( $sizes ) {
unset( $sizes[ 'medium' ] );
unset( $sizes[ 'large' ] );
unset( $sizes[ 'medium_large' ] );
unset( $sizes[ '1536x1536' ] );
unset( $sizes[ '2048x2048' ] );
return $sizes;
}
add_filter( 'big_image_size_threshold', '__return_false' );
function replace_uploaded_image($image_data) {
if (!isset($image_data['sizes']['thumbnail'])) return $image_data;
$upload_dir = wp_upload_dir();
$uploaded_image_location = $upload_dir['basedir'] . '/' .$image_data['file'];
$current_subdir = substr($image_data['file'],0,strrpos($image_data['file'],"/"));
$thumbnail_image_location = $upload_dir['basedir'] . '/'.$current_subdir.'/'.$image_data['sizes']['thumbnail']['file'];
unlink($uploaded_image_location);
rename($thumbnail_image_location,$uploaded_image_location);
$image_data['width'] = $image_data['sizes']['thumbnail']['width'];
$image_data['height'] = $image_data['sizes']['thumbnail']['height'];
unset($image_data['sizes']['thumbnail']);
return $image_data;
}
add_filter('wp_generate_attachment_metadata','replace_uploaded_image');
phpinfo();
function mytheme_add_woocommerce_support() {
add_theme_support( 'woocommerce' );
}
add_action( 'after_setup_theme', 'mytheme_add_woocommerce_support' );
single.php
будет приоритетнее по отношению к single-product.php
в подпапке темыadd_filter( 'woocommerce_admin_billing_fields', 'custom_admin_billing_fields', 10, 1 );
function custom_admin_billing_fields( $billing_fields ) {
$billing_fields['first_name']['show'] = true;
$billing_fields['last_name']['show'] = true;
return $billing_fields;
}
add_action('admin_head', 'my_custom_fonts');
function my_custom_fonts() {
echo '<style>
#order_data .order_data_column_container .address>p:first-of-type {
display: none;
}
</style>';
}
$order = new WC_Order($order_id);
$order_email = $order->billing_email;
$email = email_exists( $order_email );
$user = username_exists( $order_email );
$random_password = wp_generate_password();
$userdata = array(
'user_pass' => $random_password,
'user_login' => $order_email,
'first_name' => $order->billing_first_name,
'user_email' => $order_email,
'role' => 'customer',
);
$userid = wp_insert_user( $userdata );
ajax
только таким образом, который описан в статье Ajax в WordPress<?php
//add_action('admin_print_scripts', 'my_action_javascript'); // такое подключение будет работать не всегда
add_action('admin_print_footer_scripts', 'my_action_javascript', 99);
function my_action_javascript() {
?>
<script>
jQuery(document).ready(function($) {
var data = {
action: 'my_action',
whatever: 1234
};
// с версии 2.8 'ajaxurl' всегда определен в админке
jQuery.post( ajaxurl, data, function(response) {
alert('Получено с сервера: ' + response);
});
});
</script>
<?php
}
?>
add_action( 'woocommerce_thankyou', 'create_user_callback' );
function create_user_callback($order_id){
$order = wc_get_order( $order_id );
$order_detail['customer_first_name'] = get_post_meta( $order_id, '_billing_first_name', true );
$order_detail['customer_phone'] = get_post_meta( $order_id, '_billing_phone', true );
$order_detail['customer_email'] = get_post_meta( $order_id, '_billing_email', true );
$order_detail['customer_address'] = get_post_meta( $order_id, '_billing_address_2', true );
$customers = get_users( array( 'role' => 'customer' ) );
foreach( $customers as $customer ) :
$customers_email = get_user_meta( $customer->ID, 'billing_phone', true );
if($customers_phone!=$order_detail['customer_phone'] && $customer->user_email!=$order_detail['billing_email']) {
$userdata = array(
'user_pass' => '123',
'user_login' => $order_detail['customer_email'],
'first_name' => $order_detail['customer_first_name'],
'user_email' => $order_detail['customer_email'],
'role' => 'customer',
);
$userid = wp_insert_user( $userdata );
if ( !is_wp_error( $userid ) ) {
add_user_meta( $userid, 'billing_phone', $order_detail['customer_phone'] );
add_user_meta( $userid, 'billing_address_2', $order_detail['customer_address'] );
}
}
endforeach;
}
wc_update_new_customer_past_orders( $userid );
update_post_meta($order_id, '_customer_user', get_current_user_id());
<div class="slider grid-row" >
while ( $loop->have_posts() ): $loop->the_post(); ?>
<div class="grid-col">
<div class="img-wrapper">
<?php if ( has_post_thumbnail()) {
the_post_thumbnail('full','class=img-fluid');
} ?>
</div>
<?php endwhile; wp_reset_postdata(); ?>
</div>
{
breakpoint: 480,
settings: "unslick"
}
@media (max-width: 480px) {
.product-row {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
margin-right: -15px;
margin-left: -15px;
}
.product-col-6 {
-webkit-box-flex: 0;
-ms-flex: 0 0 50%;
flex: 0 0 50%;
max-width: 50%;
position: relative;
width: 100%;
min-height: 1px;
padding-right: 15px;
padding-left: 15px;
}
}