add_filter( 'wpcf7_validate', 'wpp_logic_for_skip_cf7_validate_in_posts', 2, 2 );
function wpp_logic_for_skip_cf7_validate_in_posts( $result, $tags ) {
$return = new WPCF7_Validation();
$invalid_fields = $result->get_invalid_fields();
/**
* Массив с полями не обязавтельными к проверке в определенных постах
* ключь - id поста в котором валидация не обязательна
* значения - тег(имя) поля которое не надо проверять
*/
// TODO: Вот тут некисло было бы сделать фильтром например $logic_for_skip = apply_filters( 'wpp_fr_cf7_skip_fields_array', [] ); так будет сильно удобнее настраивать, но для примера покатит и так
$logic_for_skip = [
4 => [
'your-name',
'your-message'
],
602 => [
'your-message'
]
];
// TODO: Этот кусок я бы не тянул в продакшен, так как значение скрытого поля _wpcf7_container_post легко подменить но queried_object тут не возвращает ID ибо, то-что было интересно я решил и валидация пропускается.
$current_id = (int)$_REQUEST[ '_wpcf7_container_post' ];
// если ошибок нет, то нихрена не делаем
if ( !is_array( $invalid_fields ) || count( $invalid_fields ) == 0 )
return $result;
//если ошибки есть, то смотрим в каких полях и если их надо пропустить пропускаем
foreach ( $invalid_fields as $invalid_field_key => $invalid_field_data ) {
if ( empty( $logic_for_skip[ $current_id ] ) || !in_array( $invalid_field_key, $logic_for_skip[ $current_id ] ) ) {
$return->invalidate( $invalid_field_key, $invalid_field_data[ 'reason' ] );
}
}
return $return;
}
Возможно ли сделать так, чтобы наведя мышкой на товар (hover) в каталоге товаров, менялась картинка товара на видео из этого же товара?
/**
* Добавление доп даты в корзину
*
* @param $cart_item_data
* @param $product_id
* @param $variation_id
*
* @return mixed
*/
function wpp_woo_additional_services_selection( $cart_item_data, $product_id, $variation_id ) {
if ( ! empty( $_REQUEST[ 'totalprice' ] ) ) {
$cart_item_data[ 'totalprice' ] = $_REQUEST[ 'totalprice' ];
}
return $cart_item_data;
}
add_filter( 'woocommerce_add_cart_item_data', 'wpp_woo_additional_services_selection', 100, 3 );
$nav = wp_nav_menu( array(
'menu' => '',
'container' => 'nav',
'container_class' => 'menu',
'container_id' => '',
'menu_class' => '',
'menu_id' => '',
'echo' => false,
'fallback_cb' => 'wp_page_menu',
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'items_wrap' => '<ul>%3$s</ul>',
'depth' => 0,
'walker' => new My_Walker_Nav_Menu(),
) );
echo preg_replace('/(<a[^>]*>)(.*?)(<\/a)/i', '$1<span>$2</span>$3', $nav);
class Wpp_Pf_Endpoints {
function __construct() {
add_action( 'init', array( __CLASS__, 'add_endpoints' ) );
add_action( 'template_include', array( __CLASS__, 'change_template' ) );
}
/**
* Add template for end_point
*
* @param $template
*
* @return mixed
*/
public static function change_template( $template ) {
$points = self::endpoint_settings();
$point = self::get_current_endpoint();
if ( empty( $point ) ) {
return $template;
}
if ( get_query_var( $point, false ) !== false ) {
$template_name = $points[ $point ]['template'];
if ( file_exists( $template_name ) ) {
return $template_name;
}
}
return $template;
}
/**
* Add endpoints for query vars.
*/
public static function add_endpoints() {
$args = self::endpoint_settings();
foreach ( $args as $one_point => $val ) {
if ( ! empty( $one_point ) ) {
$mask = ! empty( $val['places'] ) ? esc_attr( $val['places'] ) : EP_ROOT;
add_rewrite_endpoint( $one_point, $mask );
}
}
}
/**
* Get page title for an endpoint.
*
* @return array
*/
public static function endpoint_settings() {
$end_points = [];
return apply_filters( 'wpp_pf_endpoints_args', $end_points );
}
/**
* Get query current active query var.
*
* @return string
*/
public static function get_current_endpoint() {
global $wp;
$args = self::endpoint_settings();
foreach ( $args as $key => $value ) {
if ( isset( $wp->query_vars[ $key ] ) ) {
return $key;
}
}
return false;
}
}
new Wpp_Pf_Endpoints();
function add_my_test_point( $end_points ) {
$end_points['custom-product-view'] = array(
'template' => __DIR__ . '/template.php',
'places' => EP_ROOT
);
return $end_points;
}
add_filter( 'wpp_pf_endpoints_args', 'add_my_test_point' );