/**
* Fires once an existing post has been updated.
*
* @since 3.0.0
*
* @param int $post_id Post ID.
* @param WP_Post $post_after Post object following the update.
* @param WP_Post $post_before Post object before the update.
*/
do_action( 'post_updated', $post_id, $post_after, $post_before );
//функция для изменения цен с помощью числа
function wpp_price_plus() {
return 100;
}
add_filter('woocommerce_product_variation_get_regular_price', 'wpp_custom_price', 99, 2 );
add_filter('woocommerce_product_variation_get_price', 'wpp_custom_price', 99, 2 );
function wpp_custom_price( $price, $product ) {
return (float) $price + wpp_price_plus();
}
add_filter('woocommerce_variation_prices_price', 'wpp_custom_variable_price', 99, 3 );
add_filter('woocommerce_variation_prices_regular_price', 'wpp_custom_variable_price', 99, 3 );
function wpp_custom_variable_price( $price, $variation, $product ) {
// Удаление кэшированной цены продукта
wc_delete_product_transients($variation->get_id());
return (float) $price + wpp_price_plus();
}
// Обработка кэширования цен
add_filter( 'woocommerce_get_variation_prices_hash', 'add_price_plus_to_variation_prices_hash', 99, 3 );
function add_price_plus_to_variation_prices_hash( $price_hash, $product, $for_display ) {
$price_hash[] = wpp_price_plus();
return $price_hash;
}
$out = '';
$html = <<<HTML
<tr class="woocommerce-product-attributes-item woocommerce-product-attributes-item--%s">
<th class="woocommerce-product-attributes-item__label">%s</th>
<td class="woocommerce-product-attributes-item__value">%s</td>
</tr>
HTML;
$i = 1;
foreach ( $product_attributes as $attribute ):
$attribute_data = $attribute->get_data();
if ( $i !== 3 ) {
$out .= sprintf( $html, esc_attr( $attribute_data['name'] ), wc_attribute_label( $attribute_data['name'], $product->get_attribute( $attribute_data['name'] ) ) );
} else {
printf( $html, esc_attr( $attribute_data['name'] ), wc_attribute_label( $attribute_data['name'], $product->get_attribute( $attribute_data['name'] ) ) );
}
$i ++;
endforeach;
echo $out;
add_action( 'wp_default_scripts', 'include_jquery_into_footer' );
function include_jquery_into_footer( $wp_scripts ) {
if( is_admin() ) {
return;
}
$wp_scripts->add_data( 'jquery', 'group', 1 );
$wp_scripts->add_data( 'jquery-core', 'group', 1 );
$wp_scripts->add_data( 'jquery-migrate', 'group', 1 );
/**
* Для термина - product_cat
*/
add_filter( 'request', 'change_requerst_vars_for_product_cat' );
add_filter( 'term_link', 'term_link_filter', 10, 3 );
/**
* Для типа постов - product
*/
add_filter( 'post_type_link', 'wpp_remove_slug', 10, 3 );
add_action( 'pre_get_posts', 'wpp_change_request' );
function change_requerst_vars_for_product_cat($vars) {
global $wpdb;
if ( ! empty( $vars[ 'pagename' ] ) || ! empty( $vars[ 'category_name' ] ) || ! empty( $vars[ 'name' ] ) || ! empty( $vars[ 'attachment' ] ) ) {
$slug = ! empty( $vars[ 'pagename' ] ) ? $vars[ 'pagename' ] : ( ! empty( $vars[ 'name' ] ) ? $vars[ 'name' ] : ( ! empty( $vars[ 'category_name' ] ) ? $vars[ 'category_name' ] : $vars[ 'attachment' ] ) );
$exists = $wpdb->get_var( $wpdb->prepare( "SELECT t.term_id FROM $wpdb->terms t LEFT JOIN $wpdb->term_taxonomy tt ON tt.term_id = t.term_id WHERE tt.taxonomy = 'product_cat' AND t.slug = %s", array( $slug ) ) );
if ( $exists ) {
$old_vars = $vars;
$vars = array( 'product_cat' => $slug );
if ( ! empty( $old_vars[ 'paged' ] ) || ! empty( $old_vars[ 'page' ] ) ) {
$vars[ 'paged' ] = ! empty( $old_vars[ 'paged' ] ) ? $old_vars[ 'paged' ] : $old_vars[ 'page' ];
}
if ( ! empty( $old_vars[ 'orderby' ] ) ) {
$vars[ 'orderby' ] = $old_vars[ 'orderby' ];
}
if ( ! empty( $old_vars[ 'order' ] ) ) {
$vars[ 'order' ] = $old_vars[ 'order' ];
}
}
}
return $vars;
}
function term_link_filter( $url, $term, $taxonomy ) {
$url = str_replace( "/product-category/", "/", $url );
return $url;
}
function wpp_remove_slug( $post_link, $post, $name ) {
if ( 'product' != $post->post_type || 'publish' != $post->post_status ) {
return $post_link;
}
$post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link );
return $post_link;
}
function wpp_change_request( $query ) {
if ( ! $query->is_main_query() || 2 != count( $query->query ) || ! isset( $query->query[ 'page' ] ) ) {
return;
}
if ( ! empty( $query->query[ 'name' ] ) ) {
$query->set( 'post_type', array( 'post', 'product', 'page' ) );
}
}
remove_action( 'woocommerce_before_shop_loop_item_title', array( 'cherry_wc_quick_view', 'append_open_wrap' ), 0 );
Как это можно обойти, подсунув уже обработанные qTranslate данные?
add_action('wp_insert_comment', 'wpp_comment_inserted', 99, 2);
function wpp_comment_inserted($comment_id, $comment_object) {
//$comment_object - объект комментария,
//получаете пост на который он оставлен
// и если это продукт отправляете письмо
}
add_action('transition_comment_status', 'wpp_comment_approve', 10, 3);
function wpp_comment_approve($new_status, $old_status, $comment_object) {
if( $old_status !== $new_status && $new_status === 'approved' ) {
//$comment_object - объект комментария,
//получаете пост на который он оставлен
// и если это продукт отправляете письмо
}
}
function wpp_add_units_after_price_in_cart( $price, $cart_item, $cart_item_key ) {
// если единицы измерения хранятся не в в мета поле _product_units, тут получаем их
// из места их хранения по своему
$units = get_post_meta( $cart_item['product_id'], '_product_units', true );
if ( ! empty( $units ) ) {
$price .= ' ' . $units ;
}
return $price;
}
add_filter( 'woocommerce_cart_item_price', 'wpp_add_units_after_price_in_cart', 10, 3 );
if ( !class_exists( 'WPP_WC_Product_Cat_List_Walker_With_Thumb' ) ) :
class WPP_WC_Product_Cat_List_Walker_With_Thumb extends Walker {
public $tree_type = 'product_cat';
public $db_fields = array(
'parent' => 'parent',
'id' => 'term_id',
'slug' => 'slug',
);
public function start_lvl(&$output, $depth = 0, $args = array()) {
if ( 'list' != $args[ 'style' ] )
return;
$indent = str_repeat( "\t", $depth );
$output .= "$indent<ul class='children'>\n";
}
public function end_lvl(&$output, $depth = 0, $args = array()) {
if ( 'list' != $args[ 'style' ] )
return;
$indent = str_repeat( "\t", $depth );
$output .= "$indent</ul>\n";
}
public function start_el(&$output, $cat, $depth = 0, $args = array(), $current_object_id = 0) {
$output .= '<li class="cat-item cat-item-' . $cat->term_id;
if ( $args[ 'current_category' ] == $cat->term_id ) {
$output .= ' current-cat';
}
if ( $args[ 'has_children' ] && $args[ 'hierarchical' ] ) {
$output .= ' cat-parent';
}
if ( $args[ 'current_category_ancestors' ] && $args[ 'current_category' ] && in_array( $cat->term_id, $args[ 'current_category_ancestors' ] ) ) {
$output .= ' current-cat-parent';
}
$thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true );
$img_url= wp_get_attachment_url( $thumbnail_id );
$image = ! empty($img_url) ? '<img class="wpp-term-thumb" src="' . $img_url . '" alt="" />' : '';
$output .= '"><a href="' . get_term_link( (int) $cat->term_id, $this->tree_type ) . '">' . $image . _x( $cat->name, 'product category name', 'woocommerce' ) . '</a>';
if ( $args[ 'show_count' ] ) {
$output .= ' <span class="count">(' . $cat->count . ')</span>';
}
}
public function end_el(&$output, $cat, $depth = 0, $args = array()) {
$output .= "</li>\n";
}
public function display_element($element, &$children_elements, $max_depth, $depth = 0, $args, &$output) {
if ( !$element || ( 0 === $element->count && !empty( $args[ 0 ][ 'hide_empty' ] ) ) ) {
return;
}
parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
}
}
endif;
function wpp_change_widget_product_categories_walker($array) {
require_once 'Путь_к_файлу_с_добаленным_классом';
$array[ 'walker' ] = new WPP_WC_Product_Cat_List_Walker_With_Thumb;
return $array;
}
add_filter('woocommerce_product_categories_widget_args','wpp_change_widget_product_categories_walker');