php 活动门票加:WooCommerce购物车:在每个门票名称前加上适用的活动的帖子标题(如果附加到

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 活动门票加:WooCommerce购物车:在每个门票名称前加上适用的活动的帖子标题(如果附加到相关的知识,希望对你有一定的参考价值。

<?php

/*
 * Event Tickets Plus: WooCommerce Cart: Prepend each Ticket name to include
 * the applicable Event's Post Title (and Event Date if attached to a TEC event)
 * so as to help distinguish them from Tickets for multiple Events or other
 * non-Ticket Products in the Cart.
 *
 * Example: A Ticket called "Adult Ticket" for the "Day at the Zoo" event that
 * starts June 30, 2018, would appear as:
 *   Ticket for Event: Day at the Zoo on 2018-06-30: Adult Ticket
 *
 * @link https://gist.github.com/cliffordp/63abddea69b60f616c1aec1c6bdfc299 This snippet.
 * @link https://cl.ly/1l0m3q3Y0f0n A 4-minute demonstration video.
 * @link https://gist.github.com/cliffordp/5bffd372db4ebf14482574ce9bb2479c Another snippet you might be interested in.
 *
 * @param string $value          The Product name.
 * @param object $product_object The Product object, e.g. instance of WC_Product_Simple.
*/
add_filter( 'woocommerce_product_get_name', 'cliff_wootickets_prepend_event_title', 10, 2 );
function cliff_wootickets_prepend_event_title( $value, $product_object ) {
	if (
		! is_cart()
		|| ! function_exists( 'tribe_events_get_ticket_event' )
	) {
		return $value;
	}

	$post_id = $product_object->get_id();

	$event = tribe_events_get_ticket_event( $post_id );

	if ( empty( $event->ID ) ) {
		return $value;
	}

	$event_id = $event->ID;

	if (
		function_exists( 'tribe_is_event' )
		&& tribe_is_event( $event_id )
	) {
		$event_title = get_the_title( $event_id );
		$start_date  = tribe_get_start_date( $event_id, false, 'Y-m-d' );
		$value       = sprintf( '<strong>%s</strong> on %s: <strong>%s</strong>', $event_title, $start_date, $value );
	}

	$post_type = get_post_type( $event_id );

	$post_type_object = get_post_type_object( $post_type );

	$post_type_singular_label = $post_type_object->labels->singular_name;

	$value = sprintf( '%s for %s: %s',
		esc_html__( 'Ticket', 'event-tickets' ),
		$post_type_singular_label,
		$value
	);

	// Could wrap in esc_attr() for extra safety, but then remove all <strong> HTML, above.
	return $value;
}

以上是关于php 活动门票加:WooCommerce购物车:在每个门票名称前加上适用的活动的帖子标题(如果附加到的主要内容,如果未能解决你的问题,请参考以下文章

php 活动门票加 - 当WooCommerce Ticket添加到购物车时,将其他WooCommerce产品添加到购物车

php 活动门票加 - 当WooCommerce Ticket添加到购物车时,将其他WooCommerce产品添加到购物车

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

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

php 活动门票加:WooCommerce门票:将门票购买限制限制为1。

php 活动门票加:WooCommerce门票:将门票购买限制限制为1。