счетчик добавления в корзину?Сколько у текущего пользователя в корзине или сколько было вообще продано?
/**
* Получает информацию обо всех зарегистрированных размерах картинок.
*
* @global $_wp_additional_image_sizes
* @uses get_intermediate_image_sizes()
*
* @param boolean [$unset_disabled = true] Удалить из списка размеры с 0 высотой и шириной?
*
* @return array Данные всех размеров.
*/
function get_image_sizes( $unset_disabled = true ) {
$wais = &$GLOBALS['_wp_additional_image_sizes'];
$sizes = array();
foreach (get_intermediate_image_sizes() as $_size) {
if ( in_array( $_size, array( 'thumbnail', 'medium', 'medium_large', 'large' ) ) ) {
$sizes[$_size] = array(
'width' => get_option( "{$_size}_size_w" ),
'height' => get_option( "{$_size}_size_h" ),
'crop' => (bool)get_option( "{$_size}_crop" ),
);
} elseif ( isset( $wais[$_size] ) ) {
$sizes[$_size] = array(
'width' => $wais[$_size]['width'],
'height' => $wais[$_size]['height'],
'crop' => $wais[$_size]['crop'],
);
}
// size registered, but has 0 width and height
if ( $unset_disabled && ($sizes[$_size]['width'] == 0) && ($sizes[$_size]['height'] == 0) )
unset( $sizes[$_size] );
}
return $sizes;
}
global $post;
в начале функции. Хотя в аргументах функции вы получаете переменную $_product, это объект товара, то берите $_product->get_id()
от него, и $post тогда не нужен.но если зайти в товар и нажать обновить то все работает,
// Manage options hooks
add_action( 'woocommerce_product_options_inventory_product_data', 'my_woocommerce_product_options_inventory_product_data' );
add_action( 'woocommerce_process_product_meta', 'my_woocommerce_process_product_meta' );
/**
* Hook handler for woocommerce_product_options_inventory_product_data.
*
* Echo html code for our options on inventory_product_data option tab
*
* @since 1.0.0
*/
public function my_woocommerce_product_options_inventory_product_data() {
global $product, $post;
$chk_val = get_post_meta ( $post->ID , 'hdke_stock_tracker_checkbox' , true );
$thld_val = get_post_meta ( $post->ID , 'hdke_stock_tracker_threshold' , true );
echo '<div class="options_group">'; // Группировка полей
woocommerce_wp_checkbox( array(
'id' => '_hdke_stock_tracker_checkbox',
'name' => 'hdke_stock_tracker_checkbox',
'wrapper_class' => 'show_if_simple show_if_variable',
'label' => __( 'Stock tracker', $this->plugin_name ),
'description' => __( 'Enabled stock tracking for this product', $this->plugin_name ),
'cbvalue' => $chk_val ? $chk_val : 'no',
'value' => $chk_val ? $chk_val : 'no'
) );
woocommerce_wp_text_input( array(
'id' => '_hdke_stock_tracker_threshold',
'name' => 'hdke_stock_tracker_threshold',
'label' => __( 'Stock threshold', $this->plugin_name ),
'description' => __( 'Input min threshold of stock variation to include this product in dk b2b order list.', $this->plugin_name ),
'style' => 'width: 100px;',
'wrapper_class' => 'show_if_simple show_if_variable',
'desc_tip' => 'true',
'type' => 'number',
'custom_attributes' => array('step' => 'any', 'min' => '0', ),
'value' => $thld_val ? $thld_val : 0
) );
echo '</div>';
}
/**
* Hook handler for woocommerce_process_product_meta.
*
* Save user settings of our options
*
* @since 1.0.0
*/
public function my_woocommerce_process_product_meta() {
global $product, $post;
$chk_val = isset($_POST['hdke_stock_tracker_checkbox']) ? 'yes' : 'no';
$thld_val = empty($_POST['hdke_stock_tracker_threshold']) ? '0' : $_POST['hdke_stock_tracker_threshold'];
update_post_meta( $post->ID, 'hdke_stock_tracker_checkbox', $chk_val );
update_post_meta( $post->ID, 'hdke_stock_tracker_threshold', $thld_val );
}
woocommerce_checkout_order_processed
. Он активируется перед переброской на платежный шлюз, когда заказ уже полностью сформирован и проверен. По этому хуку Вы можете отправлять письмо с помощью wp_mail/**
* Переопределяем функцию, т.к. нет из нее фильтра, а тег h2 надо поменять на h3
*/
if ( ! function_exists( 'woocommerce_template_loop_product_title' ) ) {
/**
* Show the product title in the product loop. By default this is an H2.
*/
function woocommerce_template_loop_product_title() {
echo '<h3 class="' . esc_attr( apply_filters( 'woocommerce_product_loop_title_classes', 'woocommerce-loop-product__title' ) ) . '">' . get_the_title() . '</h3>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
}