php 活动日历+社区活动门票:强制全局股票被检查然后隐藏(以避免取消选中)。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 活动日历+社区活动门票:强制全局股票被检查然后隐藏(以避免取消选中)。相关的知识,希望对你有一定的参考价值。

<?php

/**
 * The Events Calendar + Community Events Tickets: Force Global Stock to be
 * checked and then hidden (to avoid unchecking), only on the Add New form.
 * 
 * Because this does not apply to the Edit Event form, you may want to modify
 * this code to your needs, such as hiding the checkbox even on the Edit form
 * but not actually forcing it checked (to avoid affecting events prior to
 * implementing this snippet.
 *
 * @link https://gist.github.com/cliffordp/c483a67a35f7032f586c6813083a998c
 */
add_action( 'wp_footer', 'cliff_community_tickets_force_global_stock' );
function cliff_community_tickets_force_global_stock() {
	if ( false === cliff_is_community_add_new_form() ) {
		return;
	}

	wp_enqueue_script( 'jquery' );
	?>
	<script type="text/javascript">
		jQuery( document ).ready( function () {
			jQuery( 'body.tribe_community_edit #tribe-global-stock-settings input#tribe-tickets-enable-global-stock' ).prop( 'checked', true ).hide();
			jQuery( 'body.tribe_community_edit #tribe-global-stock-settings label[for="tribe-tickets-enable-global-stock"]' ).hide();
			jQuery( 'body.tribe_community_edit #tribe-global-stock-settings #tribe-tickets-global-stock-level' ).show();
		} );
	</script>
	<?php
}

/**
 * Return TRUE if we are in the Community Events Add Event form. Return FALSE
 * if we are in the Edit form or Events List view.
 *
 * @return bool
 */
function cliff_is_community_add_new_form() {
	$main = tribe( 'community.main' );

	if ( empty( $main ) ) {
		// Community Events is not active (or may somehow not be loaded correctly)
		return false;
	}

	$event_post_type = Tribe__Events__Main::POSTTYPE;
	$action          = Tribe__Utils__Array::get( $main->context, 'action' );
	$ce_post_type    = Tribe__Utils__Array::get( $main->context, 'post_type', $event_post_type ); // assume event post type if not set

	// bail if we are not doing what is expected from the start
	if ( $event_post_type !== $ce_post_type ) {
		return false;
	}

	if ( 'add' === $action ) {
		return true;
	} else {
		// 'edit' for Edit form
		// or, if empty, you might be in the Community Events List view
		return false;
	}
}

以上是关于php 活动日历+社区活动门票:强制全局股票被检查然后隐藏(以避免取消选中)。的主要内容,如果未能解决你的问题,请参考以下文章

php 活动日历:社区活动门票:在社区活动列表视图上显示“付款选项”按钮。

php 活动日历:社区活动门票:在社区活动列表视图上显示“付款选项”按钮。

php 活动日历和活动门票加(ET +):如果门票适用于特定类别的活动,则禁用QR码。

php 活动日历:Eventbrite门票:自定义iframe的高度。

php 活动日历:Eventbrite门票:自定义iframe的高度。

php 活动门票加:WooCommerce:强制所有门票“单独出售”。